DOM-Based XSS: Client-Side Vulnerabilities
You'll learn how attackers exploit unsafe JavaScript code that manipulates the Document Object Model (DOM) entirely in the browser, without ever touching the server.
The Key Difference
Unlike Reflected XSS (where malicious input travels to the server and back) or Stored XSS (where it's saved in a database), DOM-Based XSS happens entirely in your browser. The vulnerability exists in client-side JavaScript code that reads user-controllable data and writes it to dangerous DOM locations without proper sanitization.
How It Works
Think of your browser's JavaScript as a construction crew remodeling a house (the webpage). DOM-Based XSS occurs when the crew follows dangerous instructions from an untrusted blueprint without checking if those instructions are safe.
Common dangerous patterns include:
- Reading data from
location.hash,location.search, ordocument.referrer - Passing that data directly into dangerous "sinks" like
innerHTML,document.write(), oreval()
Example scenario: A page uses JavaScript to read a URL parameter and display a welcome message:
// Vulnerable code - never reaches the server
var name = location.hash.substring(1);
document.getElementById('welcome').innerHTML = "Hello " + name;
If an attacker crafts a URL like page.html#<img src=x onerror=alert('XSS')>, the malicious script executes immediately in the victim's browser. The server never sees this payload—it all happens client-side.
Why It's Harder to Detect
Traditional web application firewalls can't catch DOM-Based XSS because the malicious payload never appears in HTTP requests to the server. It lives entirely in the URL fragment (after the #) or is manipulated purely by JavaScript.
Key Takeaway: DOM-Based XSS exploits unsafe JavaScript that reads user input and writes it to dangerous DOM locations entirely in the browser, making it invisible to server-side security controls.