Web security and the OWASP Top 10
The mistakes behind most website breaches and their fixes, each shown as vulnerable code next to fixed code: broken access control, SQL injection, cross-site scripting, cross-site request forgery and weak logins.
About 12 hours of study
Learning objectives
- Name the OWASP Top 10 risks and fix broken access control
- Stop SQL injection with parameterized queries
- Stop cross-site scripting with output encoding and a Content-Security-Policy
- Defend forms with CSRF tokens and SameSite cookies, and logins with limits and safe sessions
Lessons
- 1
The OWASP Top 10 and broken access control
The map of web application risks: the OWASP Top 10 categories in plain words, and the top one, broken access control, with the classic insecure direct object reference and its fix.
- 2
SQL injection and parameterized queries
How pasting user input into SQL lets one input box change what a query means, the classic payloads shown on a fake in-page table, and the fix: parameterized queries, plus allow-lists and least privilege.
- 3
Cross-site scripting (XSS)
How text treated as HTML lets an attacker's script run in every reader's browser, the stored, reflected and DOM-based kinds, and the fix: output encoding, with a Content-Security-Policy and HttpOnly cookies as extra layers.
- 4
Cross-site request forgery (CSRF)
How another site can make your browser send a request to a site where you are logged in, why it targets actions and not data, and the defences: CSRF tokens, SameSite cookies and Origin checks.
- 5
Broken authentication and sessions
Credential stuffing, password spraying and stolen sessions, and the defences: rate limits with growing delays, safe session IDs that are renewed and expired, generic errors and safe password resets.
Module practice
- Check who owns the recordEasy
- Role-based accessMedium
- Find id-guessing in a logHard
- What does the database receive?Easy
- Does the input break out?Medium
- A tiny WHERE evaluatorHard
- Escape for HTMLEasy
- Would this HTML run code?Medium
- An allow-list sanitizerHard
- Check CSRF tokensEasy
- Is the cookie sent?Medium
- Audit endpoints for CSRFHard
- One message for every failureEasy
- Growing delays per accountMedium
- Detect password sprayingHard