TL;DR: Cross-site scripting remains a browser-side exploitation path where unvalidated input, unsafe rendering, and weak client-side controls let attackers run scripts in a trusted session, according to StackHawk. The practical issue is not just finding XSS, but preventing stored, reflected, and DOM-based variants before they reach users.
At a glance
What this is: StackHawk explains that XSS remains a live web application risk because untrusted input can still reach the browser without adequate validation, encoding, or client-side containment.
Why it matters: For IAM and application security teams, XSS matters because it can turn a normal user session into an attacker-controlled browser context, exposing data and session state.
Context
Cross-site scripting is a browser-side injection problem, not just a coding mistake. It appears when applications accept untrusted input and later render that content in a way the browser treats as executable script. The identity angle is practical: once script runs in a trusted session, the attacker can act through the victim’s authenticated context, which makes session-bound controls and front-end sanitisation part of access security.
The control gap is usually a combination of weak input handling, incomplete output encoding, and overconfidence in client-side behaviour. Server-side validation helps, but DOM-based XSS shows why the browser can become the enforcement point if untrusted data reaches dynamic rendering paths. That makes XSS a recurring application security issue rather than an edge case, especially in applications that mix user input, URLs, comments, and client-side templating.
Key questions
Q: What breaks when input is not encoded before rendering in web apps?
A: Untrusted data can become executable script when the browser renders it in a trusted page context. That breaks the boundary between text and code, which is why users can be exposed through reflected, stored, or DOM-based XSS. The practical failure is not only data leakage but also session abuse, because the attacker can act through the victim’s authenticated browser state.
Q: Why does XSS remain risky even when users must already be authenticated?
A: XSS is dangerous after login because the attacker operates inside the victim’s trusted browser session. If scripts can read tokens, change page actions, or redirect traffic, authentication stops being a boundary and becomes an asset the attacker can abuse. That is why session protection and output controls both matter.
Q: Where do teams most often miss DOM-based XSS risk?
A: Teams often focus on server responses and miss unsafe client-side transformations that write URL or form data into the DOM. That is where browser-side execution happens without server validation catching it. The highest-risk spots are dynamic page fragments, templating logic, and any code that concatenates untrusted input into active page content.
Q: How should security teams layer CSP with encoding controls?
A: Use encoding and validation to prevent injection first, then apply CSP to limit where scripts can execute if a defect slips through. CSP is a containment control, not a substitute for safe rendering. Teams should still remove inline execution paths and keep the policy as restrictive as the application can tolerate.
Technical breakdown
How reflected XSS turns a URL into executable script
Reflected XSS happens when an application takes data from a request, such as a query parameter, and sends it back into the response without escaping it. The browser then interprets attacker-controlled content as code instead of text. This usually depends on a trusted page reflecting the payload immediately, which is why links sent through email, forums, or social media are so effective. The application does not need to be compromised in advance. The vulnerability is the unsafe rendering path itself, not the delivery channel.
Practical implication: encode all untrusted output before it reaches HTML, attribute, or script contexts.
Why stored and DOM-based XSS fail in different places
Stored XSS persists because malicious content is saved by the application and later served to other users, often through comments, profiles, or shared content. DOM-based XSS is different because the payload is introduced or transformed in the browser itself, often by client-side code that writes untrusted values into the DOM. That means server-side checks alone can miss it. The real technical issue is context loss: once data is moved from a safe transport format into a browser execution context, the application must preserve encoding discipline end to end.
Practical implication: review both server-rendered and client-rendered paths for unsafe DOM writes and persistent storage of active content.
Why CSP is a containment control, not a complete fix
Content Security Policy limits where the browser can load or execute scripts from, which helps reduce the impact of XSS. But CSP does not replace encoding or input validation, because a weak policy, inline exceptions, or permissive script sources can still leave exploitable paths. In practice, CSP works best as a containment layer after the application has already tried to prevent injection. It is especially useful when legacy code or third-party front-end components make full eradication difficult.
Practical implication: treat CSP as a backstop and keep tightening it while fixing the underlying injection points.
Threat narrative
Attacker objective: The attacker wants to run code in a trusted browser session so they can steal data, hijack activity, or act as the user.
- Entry begins when an attacker submits malicious script through a text field, URL parameter, or comment field in a vulnerable web application.
- Credential or session access follows when the browser executes the payload inside a trusted user session and exposes cookies, personal data, or authenticated actions.
- Impact occurs when the attacker impersonates the user, reads sensitive information, or manipulates the application through the victim's browser context.
Breaches seen in the wild
- ASP.NET machine key attacks 2025: Developers copied ASP.NET machine keys from public sources; attackers used one to run Godzilla via ViewState. Microsoft found 3,000+ such keys.
- United Nations breach 2021: Sakura Samurai used exposed Git credentials to reach 100,000+ UNEP staff records, then reported the flaw through the UN disclosure programme.
Read and download The State of NHI & AI Agent Breach Report 2026, covering 200+ breaches impacting Non-Human Identities including AI Agents.
NHI Mgmt Group analysis
XSS is still a session abuse problem, not just a code-quality issue. The attack works because applications let untrusted input cross the boundary into trusted rendering contexts. Once the browser executes that content, the attacker inherits the user's active session state and can operate inside the application as if they were the user. Practitioners should treat this as a control-plane failure for browser-based trust.
DOM-based XSS shows why front-end logic now carries governance weight. Many teams still frame XSS as a server-side output problem, but modern client-heavy applications move risk into JavaScript, templating, and DOM manipulation. That shifts the governance burden to where data is transformed, not just where it is stored. Teams need explicit ownership for browser-side trust decisions, not only back-end review.
Input handling and encoding are the primary preventive controls, while CSP is a containment layer. The strongest named concept here is browser trust boundary leakage, where data crosses from user-controlled input into executable page context without sufficient separation. In practice, that means the security architecture has failed to preserve the difference between text and code. Practitioners should design for that boundary first, then use CSP to reduce blast radius.
XSS prevention is a continuous assurance problem because every rendering path can regress. The article's examples show how small changes in query handling, comment storage, or DOM writes can reintroduce exposure after a period of safety. That makes testing, code review, and runtime validation a lifecycle issue, not a one-time fix. Security teams should assume the control will degrade unless it is checked repeatedly.
Automation belongs in the application security pipeline, but it does not replace secure design. StackHawk's testing angle points to a broader governance lesson: finding XSS after deployment is useful, but preventing it requires secure coding patterns and browser policy enforcement. For practitioners, the right model is layered control with ownership at development, review, and runtime stages.
From our research library:
- The average time to mitigate a leaked secret is 36 hours, highlighting the operational burden of manual remediation processes, according to the 2024 State of Secrets Management Survey.
- The average estimated time to remediate a leaked secret is 27 days, despite 75% of organisations expressing strong confidence in their secrets management capabilities, according to the State of Secrets in AppSec.
- Read next: Access Reviews and Certification Guide
What this signals
Browser trust boundary leakage: XSS remains dangerous because applications still convert untrusted input into executable page content. The governance problem is not only whether a page is sanitized once, but whether every rendering path preserves the text-versus-code boundary as features change.
Security teams should treat front-end rendering as part of the application security control surface, not a cosmetic layer. That means code review, test automation, and policy enforcement must cover client-side templates, persistent content, and any flow that writes into the DOM.
CSP is useful when it is restrictive enough to contain residual exposure, but it cannot compensate for weak encoding discipline. The practical signal for practitioners is simple: if input handling is inconsistent, the browser becomes the enforcement gap, not the protection boundary.
For practitioners
- Implement context-aware output encoding Encode untrusted data differently for HTML text, attribute values, JavaScript, and URL contexts so the browser never interprets user input as executable content.
- Remove unsafe DOM writes Audit client-side code for document.write, innerHTML, and similar patterns that place request data directly into the DOM without sanitisation.
- Tighten Content Security Policy rules Restrict script sources, remove unnecessary inline execution, and use CSP as a containment layer that reduces the impact of missed encoding defects.
- Test XSS paths in the delivery pipeline Run automated security tests against reflected, stored, and DOM-based input paths before release so regressions are caught where code changes occur.
- Review user-generated content flows Check comments, profile fields, search results, and other persistent content for unsafe storage and later rendering of active script payloads.
Key takeaways
- XSS persists when applications fail to keep user-controlled input out of executable browser contexts.
- The article's examples show that reflected, stored, and DOM-based XSS each exploit a different rendering path, but all depend on weak handling of untrusted data.
- Encoding, validation, and CSP work best as layered controls, with secure rendering doing most of the prevention and CSP limiting blast radius.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
MITRE ATT&CK addresses the attack and risk surface, while OWASP ASVS and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP ASVS | V1 — Encoding and Sanitization | XSS prevention here depends on encoding untrusted input before it reaches the browser. |
| V15 — Secure Coding and Architecture | The article centers on secure rendering patterns and avoiding dangerous browser-side code paths. | |
| Recommendation — Apply V1 controls to encode and sanitise all untrusted data by output context. Use V15 to remove unsafe rendering patterns from application architecture and code. | ||
| NIST CSF 2.0 | PR.DS-01 — Data-at-rest is protected | User content and session data exposed by XSS require strong protection of sensitive data. |
| PR.PS-01 — Configuration management | CSP is a browser security configuration that constrains script execution sources. | |
| Recommendation — Protect sensitive browser-exposed data so a script execution defect reveals less value. Harden browser security configuration with restrictive CSP and related platform settings. | ||
| MITRE ATT&CK | TA0001;TA0009 — Initial Access; Collection | XSS provides initial browser execution that enables collection of session data or content. |
| Recommendation — Map XSS payload execution to Initial Access and Collection when tuning detection and testing. | ||
Key terms
- Cross-Site Scripting (XSS): A web application flaw where untrusted input is rendered in a way that causes script to execute in a user’s browser. It usually appears when output encoding, templating, or input handling is inconsistent across code paths and frameworks.
- Reflected Xss: A reflected XSS flaw occurs when an application takes untrusted input from a request and immediately includes it in the response without safe encoding. The payload is not stored server-side, but it can still execute in the victim’s browser when they follow a crafted link or submit malicious input.
- Stored Xss: Stored XSS happens when an application saves malicious script in backend content such as comments, profiles, or posts, then serves it to other users later. Because the payload persists, one successful injection can trigger repeated execution across many authenticated sessions.
- Dom-based Xss: DOM-based XSS is a client-side injection flaw where browser JavaScript writes unsafe data into the page’s DOM. The server may never process the payload, which makes this class harder to catch with server-side filters alone and increases the importance of safe front-end coding patterns.
Deepen your knowledge
NHI Foundation Level course, the industry's only accredited NHI security programme, covers NHI governance, IAM, and secrets management through an identity-first lens. It is designed for practitioners who need a common control vocabulary across human identity, machine identity, and access governance.
Published by the NHIMG editorial team on August 1, 2026.
Updated on October 13, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org