Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
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.

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.
Every instance is a path from a source to a sink. Sources are the places untrusted data enters client-side code:
location.hash, location.search, and location.pathnamedocument.referrer and window.namepostMessage event data, particularly where the sender’s origin is not checkedlocalStorage, sessionStorage, or cookiesSinks are the APIs that give that data meaning:
innerHTML, outerHTML, insertAdjacentHTML, and document.writeeval, Function, setTimeout, and setInterval when passed a stringlocation, src, or href, which allows a javascript: URLbypassSecurityTrustHtml, React’s dangerouslySetInnerHTML, and Vue’s v-htmlA one-line example: document.getElementById('out').innerHTML = decodeURIComponent(location.hash.slice(1)). A URL ending in #<img src=x onerror=alert(1)> executes immediately.
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.
textContent instead of innerHTML, setAttribute with a validated value instead of string concatenation, and never a string argument to setTimeout.javascript: and data: are rejected.postMessage handler, and treat the payload as untrusted even when the origin matches.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.
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.
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.
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.
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.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.