Skip to content
Vol. 1 · Ed. 2026
CyberGlossary
Entry № 347

DOM-Based XSS

What is DOM-Based XSS?

DOM-Based XSSAn XSS variant where the injection and execution happen entirely in the browser as client-side JavaScript writes untrusted data into a sink without sanitization.


DOM-based XSS (also called Type-0) is a cross-site scripting flaw whose root cause lives entirely in client-side code. A trusted source — for example location.hash, document.referrer, window.name, postMessage, or localStorage — is passed without sanitization into a dangerous DOM sink such as innerHTML, document.write, eval, or jQuery.html. The server never sees the payload, which makes the vulnerability invisible to traditional WAFs and server logs. Defenses include using safe APIs like textContent, leveraging Trusted Types in modern browsers, deploying a strict Content Security Policy, and auditing JavaScript with tools that track tainted-data flow from sources to sinks.

Examples

  1. 01

    document.getElementById('out').innerHTML = location.hash.substring(1);

  2. 02

    A SPA router using window.location to render unsanitized HTML into a template slot.

Frequently asked questions

What is DOM-Based XSS?

An XSS variant where the injection and execution happen entirely in the browser as client-side JavaScript writes untrusted data into a sink without sanitization. It belongs to the Attacks & Threats category of cybersecurity.

What does DOM-Based XSS mean?

An XSS variant where the injection and execution happen entirely in the browser as client-side JavaScript writes untrusted data into a sink without sanitization.

How does DOM-Based XSS work?

DOM-based XSS (also called Type-0) is a cross-site scripting flaw whose root cause lives entirely in client-side code. A trusted source — for example location.hash, document.referrer, window.name, postMessage, or localStorage — is passed without sanitization into a dangerous DOM sink such as innerHTML, document.write, eval, or jQuery.html. The server never sees the payload, which makes the vulnerability invisible to traditional WAFs and server logs. Defenses include using safe APIs like textContent, leveraging Trusted Types in modern browsers, deploying a strict Content Security Policy, and auditing JavaScript with tools that track tainted-data flow from sources to sinks.

How do you defend against DOM-Based XSS?

Defences for DOM-Based XSS typically combine technical controls and operational practices, as detailed in the full definition above.

What are other names for DOM-Based XSS?

Common alternative names include: Type-0 XSS, Client-side XSS.

Related terms

See also