Join our Newsletter — 33% off our NHI Course
Home› Glossary› Cyber Security› DOM-Based Cross-Site Scripting
Cyber Security

DOM-Based Cross-Site Scripting

← Back to Glossary
By NHI Mgmt Group Updated October 23, 2026 Domain: Cyber Security

DOM-Based Cross-Site Scripting is a web attack where malicious script is executed by manipulating a page’s browser-side Document Object Model rather than the server response. The flaw appears when JavaScript reads unsafe input from the URL, form fields, or storage and writes it into the page without proper output encoding or sanitization.

How DOM-Based Cross-Site Scripting Works

DOM-based XSS happens entirely in the browser, so the server can appear harmless while client-side JavaScript turns unsafe input into executable code. That distinction matters because the flaw often lives in page logic, not in the HTTP response itself.

Attackers look for sources such as URL fragments, query strings, form inputs, postMessage data, local storage, or cookies when scripts read from those values and later insert them into the DOM. The dangerous step is usually a sink such as innerHTML, document.write, eval, or unsafe template rendering.

Why DOM XSS Is Dangerous

Because the browser executes the payload in the trusted origin, DOM XSS can expose session data, alter page behaviour, steal tokens, or silently redirect users. It can also bypass server-side filtering if the vulnerable code never sends the malicious string back from the backend.

DOM XSS is especially dangerous in single-page applications and other highly dynamic interfaces, where client-side routing and rendering create many more places for untrusted data to cross into script execution. The risk grows when the page mixes multiple encoding contexts, such as HTML, attributes, URLs, and JavaScript strings, without treating each one differently.

For a broader view of related attack patterns, the Web Application Attacks Guide covers how XSS fits into the wider application attack surface.

How Teams Find Exposure to DOM XSS

Exposure review starts with the code paths that move browser-controlled data into the DOM. Teams typically inspect JavaScript frameworks, search for known sink functions, and trace whether input is decoded, normalised, or written back without context-aware encoding.

Asset inventory also matters, because DOM XSS often hides in legacy pages, shared front-end components, third-party widgets, and feature flags that are easy to overlook. The most useful review is not just “does the app have XSS?”, but “where does untrusted data enter the DOM and which sinks can execute it?”

The Cross-Site Scripting (XSS) Prevention Guide is the most direct companion resource for tracing those source-to-sink patterns and the controls that break them.

Prevention and Detection for DOM-Based XSS

Prevention depends on context-sensitive output encoding, sanitisation where HTML is genuinely required, and avoiding dangerous sinks unless they are tightly controlled. Security teams also rely on browser-side hardening, especially Content Security Policy and Trusted Types, to reduce the chance that a single bad write becomes script execution.

Detection is strongest when testing combines manual review, dynamic scanning, and browser instrumentation. After a fix, teams should review whether the payload could have executed before the patch, because DOM XSS often leaves little server-side evidence and may only be visible in client logs, telemetry, or unusual DOM mutation patterns.

Implementation guidance for these controls is also discussed in the XSS Prevention Guide, which is useful when turning the concept into secure coding practice.

Risk and Threat Considerations

DOM XSS is risky because the browser runs attacker-controlled script inside the legitimate origin, which can expose data, hijack user actions, and preserve access through stolen browser state. The threat is often missed because traditional server-side filters and web logs may not show the vulnerable write path.

Failure mechanism: A page reads untrusted browser-side input and places it into an executable DOM sink without the right encoding, sanitisation, or policy enforcement, so the payload is interpreted as code.

Impact: Attackers can steal data, tamper with page content, impersonate the user in-session, or chain the issue into broader account compromise and fraud.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP ASVS, CIS Controls v8 and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP ASVSV1 — Encoding and SanitizationDOM XSS is prevented by context-aware encoding and sanitization of untrusted input.
V13 — ConfigurationTrusted Types and CSP hardening are configuration controls that reduce DOM XSS execution paths.
V16 — Security Logging and Error HandlingClient-side XSS often requires logging and monitoring to confirm exploitation and validate fixes.
Recommendation — Apply context-specific encoding and sanitization before untrusted data reaches the DOM. Enable browser security policies that restrict unsafe DOM sinks and script execution. Instrument client-side logging and error handling to detect suspicious DOM mutation behavior.
CIS Controls v8CIS-16 — Application Software SecurityDOM XSS is an application security defect that belongs in secure coding and testing controls.
Recommendation — Build XSS testing and secure coding checks into application security assurance.
NIST SP 800-53 Rev 5SI-10 — Information Input ValidationDOM XSS arises when untrusted input is accepted and processed without proper validation or handling.
SC-18 — Mobile CodeDOM XSS delivers executable script through browser-side code execution paths.
Recommendation — Validate and constrain browser-handled inputs before code uses them in execution paths. Restrict unsafe client-side code execution and review browser scripting surfaces.

Practitioner Guidance

Why practitioners should care: DOM XSS is a front-end code quality issue that quickly becomes an authentication and trust problem once the payload runs in the user’s session. Teams should treat it as a release-blocking defect when scripts process untrusted input in the browser.

What to watch for: Any use of innerHTML, eval, document.write, dynamic script creation, or framework escape hatches deserves special review, especially when the data originates from the URL, storage, or cross-window messaging. These are the places where “just rendering text” can become script execution.

Practitioner takeaway: The safest pattern is to keep untrusted data as text, not markup, and to verify both the source and the sink every time client-side code transforms input.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 23, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org