Concept
Classification of XSS
The three types of XSS — Reflected, Stored, and DOM-based — are not classified by the actual JavaScript payload.
They are classified by how the untrusted data travels through the application before it executes.
1. Reflected XSS:
The malicious input:
Attacker → Server → Immediate response → Browser
The input is reflected back in the same request/response.
Example: A search parameter is immediately displayed on the search results page.
2. Stored XSS:
The malicious input:
Attacker → Server → Database → Later response → Browser
The application stores the malicious input and displays it later.
Example: A malicious comment is stored in the database and executes whenever someone views the comment.
3. DOM-based XSS
The malicious input:
Attacker → Browser → JavaScript → DOM
The server doesn't need to process the malicious input. JavaScript already running in the browser takes untrusted data and inserts it into the page unsafely.
Example: Client-side JavaScript reads a value from the URL fragment and writes it into the page.