Handbooks / Web Security (OWASP) / Chapter 2
Cross-Site Scripting (XSS)
7 pages · ~5 min✓ Reviewed
Builds on Injection. Next up: Authentication and Sessions.
XSS Mental Model: Stored, Reflected, DOM
1. What XSS Is
- Attacker data runs as code in the victim's browser
- Runs with the page's origin: reads DOM, sends requests, acts as the user
2. Three Types
| Stored | Reflected | DOM | |
|---|---|---|---|
| Payload | saved (comment, profile name) | in request (query, form field) | client source to sink |
| Needs a click? | no | yes, crafted URL | yes |
| Server sees it | yes | yes | often never (#fragment) |
| Impact | every viewer | one victim | one victim |
3. DOM: Source to Sink
- Sources:
location.hash,location.search,document.referrer,postMessage - Sinks:
innerHTML,document.write,eval,setTimeout(string),element.href location.hash,postMessageskip the server;location.searchis sent