Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is DOM-Based XSS?

DOM-based XSS occurs entirely in the browser: client-side JavaScript reads attacker-controlled data and writes it into a dangerous sink, often without the payload ever reaching the server.

Illustration for the cybersecurity term DOM-Based XSS
Home / Blog / Cybersecurity Terms / What Is DOM-Based XSS?
17 November 2026

What Is DOM-Based XSS?

What Is DOM-Based XSS?

DOM-based cross-site scripting is the variant that never involves the server in the injection. The page is delivered exactly as the developer wrote it; the vulnerability lies in the JavaScript that runs afterwards, which reads a value the attacker controls and passes it to an API that converts strings into markup or code. Because the payload can travel in a URL fragment, it may never leave the browser at all, which makes server logs and web application firewalls equally useless as controls.

Sources and Sinks

Every instance is a path from a source to a sink. Sources are the places untrusted data enters client-side code:

Sinks are the APIs that give that data meaning:

A one-line example: document.getElementById('out').innerHTML = decodeURIComponent(location.hash.slice(1)). A URL ending in #<img src=x onerror=alert(1)> executes immediately.

Why Server-Side Defences Do Not Apply

Fragments are not transmitted in HTTP requests, so a filter at the edge sees nothing suspicious. Output encoding on the server protects the HTML it generates, but the dangerous write happens later, in code that the server never inspects. This also explains why DOM-based cases are under-reported: a scanner that compares requests to responses finds nothing, and only tools that execute the page and trace data flows through the DOM detect them. Burp Suite’s DOM Invader and the browser developer tools’ breakpoints on DOM modification are the practical instruments here.

Libraries are a frequent cause rather than a bystander. jQuery’s selector function treated a string beginning with a character other than # as HTML, which produced a long tail of injections; CVE-2020-11022 and CVE-2020-11023 covered related issues in jQuery before version 3.5.0, where HTML passed to DOM manipulation methods could execute despite being passed through a sanitiser.

Fixing It Properly

  1. Prefer safe sinks. textContent instead of innerHTML, setAttribute with a validated value instead of string concatenation, and never a string argument to setTimeout.
  2. Sanitise when markup is genuinely required. DOMPurify is the accepted library; hand-written regular expressions are not a substitute for a parser-based sanitiser.
  3. Validate URLs against an allow-list of schemes before assigning them, so javascript: and data: are rejected.
  4. Check the origin on every postMessage handler, and treat the payload as untrusted even when the origin matches.
  5. Adopt Trusted Types. Enforced through a Content Security Policy directive, it makes assignment of a plain string to a dangerous sink throw an error, which converts an entire vulnerability class into a build-time problem. Chromium browsers support it today.
  6. Keep front-end libraries current, and track them with software composition analysis in the same way as server-side dependencies.

Where It Shows Up in Testing

Single-page applications, client-side routers, analytics and tag manager snippets, and any feature that restores state from a URL are the usual locations. Message handlers between a page and an embedded iframe are another, especially in payment and chat widgets. The broader context, including reflected and stored variants, is covered in our article on cross-site scripting, and our web application security testing traces these flows in the running front end rather than relying on request and response comparison.

FAQ – Frequently Asked Questions

How Is DOM-Based XSS Different from Reflected XSS?

In reflected XSS the server receives the payload and includes it in the HTML it returns, so the flaw is in server-side rendering. In DOM-based XSS the server returns an unchanged page and client-side JavaScript introduces the payload afterwards. The practical consequence is that the payload can hide in a URL fragment, which browsers never send, so no server-side control ever sees it.

Will a Web Application Firewall Block It?

Usually not. A firewall inspects HTTP requests, and the classic DOM-based payload travels in the fragment after the hash symbol, which the browser does not transmit. Even when the payload is in a query string, the firewall cannot tell whether client-side code will reach a dangerous sink. The fix has to be in the JavaScript itself.

Does React or Angular Protect Us Automatically?

Largely, because both escape interpolated values by default. The exceptions are deliberate escape hatches: dangerouslySetInnerHTML in React, bypassSecurityTrustHtml in Angular, and v-html in Vue. Each one disables the framework’s protection for that value. Searching the codebase for those identifiers finds most DOM-based issues in a modern front end within minutes.

What Are Trusted Types?

A browser feature that requires dangerous DOM sinks to receive a specially created object rather than a plain string. Enabled through a Content Security Policy directive, it causes any unchecked assignment to throw, so unsafe patterns surface during development instead of in production. Support is currently limited to Chromium-based browsers, so it complements rather than replaces output handling.

Related Terms

You May Be Interested In These

What Is Network Detection and Response (NDR)?

Cybersecurity Terms

17 November 2026

What Is Network Detection and Response (NDR)?

Read More
What Is BadUSB?

Cybersecurity Terms

17 November 2026

What Is BadUSB?

Read More
What Is Evil-WinRM?

Cybersecurity Terms

17 November 2026

What Is Evil-WinRM?

Read More