Web security protects sites and web applications, and the people who use them, from abuse. A browser runs code from many origins at once and a server answers anyone on the internet, so the rules about who may read what, and who may act as whom, are the heart of the field.
Key concepts
- Same-origin policy: the browser's basic wall; scripts from one origin cannot freely read another's data.
- Injection: untrusted input reaching an interpreter, such as SQL or HTML, as code; the cure is parameters and context-aware encoding.
- Sessions and cookies: how a server remembers a user; flags like HttpOnly, Secure and SameSite limit their exposure.
- Request forgery: a page that makes the browser send a request the user never intended; tokens and SameSite cookies defend.
- Transport and headers: HTTPS everywhere, plus headers such as Content-Security-Policy that tell the browser what is allowed.
Vocabulary
- XSS: cross-site scripting, attacker-controlled script running in a victim's page.
- CSRF: cross-site request forgery.
- CORS: the mechanism that lets a server relax the same-origin policy for chosen origins.
- TLS: the protocol that encrypts and authenticates the connection.
What to study, in order
- HTTP by hand: requests, responses, cookies and redirects, watched in the browser's developer tools.
- The same-origin policy and CORS, with two small servers of your own on different ports.
- Build a small login form, then protect it: hashing, sessions, CSRF tokens, secure cookies.
- Work through a deliberately vulnerable web app that you host locally, finding each flaw class and then patching it.
- Add a Content-Security-Policy to a real project and fix what breaks.