Types of XSS: Stored, Reflected, and DOM-Based
You'll learn how the three main types of Cross-Site Scripting attacks differ in where malicious scripts are stored and how they're executed.
The Three Flavors of XSS
Not all XSS attacks work the same way. Understanding where the malicious payload lives and how it reaches victims is crucial for both exploiting vulnerabilities during testing and defending against them.
Stored XSS (Persistent XSS) occurs when malicious script is saved permanently in the target system—typically in a database. When other users view the compromised data (like a comment, forum post, or profile field), the script executes in their browsers. This is the most dangerous type because it affects multiple users automatically without requiring them to click a specific link.
Analogy: Think of graffiti spray-painted on a wall—everyone who walks by sees it.
Reflected XSS (Non-Persistent XSS) happens when malicious script is immediately reflected back to the user from the server without being stored. The payload typically arrives via URL parameters or form data and is echoed in the response. Attackers must trick victims into clicking malicious links or submitting crafted forms.
Analogy: Like shouting into a canyon—your voice bounces back once, but isn't stored there.
DOM-Based XSS is entirely client-side. The vulnerability exists in JavaScript code that processes user input and dynamically updates the DOM without proper sanitization. The malicious payload never reaches the server—it's executed purely in the browser by manipulating client-side scripts.
Analogy: Like a calculator malfunction—the problem is in the device itself, not what was sent from elsewhere.
Each type requires different detection techniques and mitigation strategies, though input validation, output encoding, and Content Security Policy help defend against all three.
Key Takeaway: Stored XSS persists in databases and auto-executes for multiple users; reflected XSS bounces back immediately from server responses; DOM-based XSS exploits client-side JavaScript without server involvement.