Cross-Site Scripting (XSS)
At a Glance
- Attacker injects malicious scripts into web pages viewed by other users
- Three types: Stored (persistent), Reflected (non-persistent), DOM-based
- Primary defense: output encoding and Content Security Policy
- Can perform authorized-looking actions, redirect users, or modify page content
- Covered by the Injection category in the current OWASP Top 10
Why XSS Matters
OWASP Top 10:2025 includes XSS under A05 Injection. It occurs when an application places untrusted data into an executable browser context without context-appropriate output encoding, sanitization, or safe DOM APIs. Common descriptions include stored, reflected, and DOM-based XSS.
The impact of XSS ranges from nuisance (page defacement) to critical (session hijacking, credential theft). An attacker exploiting XSS on a banking site could transfer funds. On a social media site, they could spread malware to all of a user's contacts.
Defenses depend on context: safe framework APIs, context-appropriate output encoding, HTML sanitization when HTML is intentionally allowed, URL validation, and avoiding unsafe DOM sinks. A strict nonce- or hash-based CSP is valuable defense-in-depth in supporting browsers but does not fix the injection flaw.
How to Check
DomainOptic can report whether a CSP header is present, but it does not test application-level XSS or prove that the policy is strict. Use code review, framework-specific analysis, and authorized dynamic testing for the actual sources and sinks.