DOM-Based XSS Attacks
What you'll learn: You'll understand how XSS vulnerabilities can hide entirely in client-side JavaScript, exploiting the way scripts manipulate the DOM without ever sending malicious payloads to the server.
The Client-Side Trap
Unlike Reflected and Stored XSS (which involve server-side processing), DOM-Based XSS occurs purely in the browser. The vulnerability exists in JavaScript code that reads user-controlled input from the DOM and writes it back unsafely—all without the malicious data ever touching the server.
Think of it like a self-inflicted wound: your own JavaScript code becomes the weapon that executes the attack, processing dangerous input right in the user's browser.
How It Works
DOM-Based XSS exploits JavaScript that reads from sources (user-controllable data) and writes to sinks (dangerous execution contexts) without proper validation.
Common sources:
window.location.hash(URL fragment after #)document.URLdocument.referrer
Dangerous sinks:
document.write()innerHTMLeval()setTimeout()with string arguments
For example, JavaScript that reads a name from the URL hash and displays it: the code grabs window.location.hash, extracts a value, and inserts it directly into the page using innerHTML. An attacker crafts a URL with a malicious hash containing script tags, and when the victim's browser runs that JavaScript, it executes the injected code—no server involvement required.
Why It's Different
The server never sees the attack payload (it's often in the URL fragment), making traditional server-side defenses ineffective. The vulnerability lives in your client-side code logic.
Key Takeaway: DOM-Based XSS exploits insecure JavaScript that processes user input entirely in the browser, requiring developers to sanitize data within client-side code before inserting it into dangerous DOM operations.