1 DOM XSS Sources and Sinks
DOM-based XSS occurs entirely in the browser. Attacker-controlled data flows from a DOM source to a dangerous sink without server involvement, bypassing server-side sanitization.
Common sources:
location.hash,location.search,location.hrefdocument.referrerwindow.name- localStorage, sessionStorage
postMessageevent data
Dangerous sinks:
// These sinks interpret strings as HTML/JS — DANGEROUS with user data
element.innerHTML = userInput;
element.outerHTML = userInput;
document.write(userInput);
eval(userInput);
new Function(userInput);
location.href = userInput; // javascript: URI
scriptTag.src = userInput;Classic DOM XSS example:
// URL: https://example.com/page#<img src=x onerror=alert(1)>
const msg = location.hash.slice(1); // Source
document.getElementById("output").innerHTML = msg; // Sink!