Stored & Reflected Cross-Site Scripting (XSS) in Modern React & Next.js
React escapes strings in JSX, but dangerouslySetInnerHTML, javascript: URLs, and unescaped SSR hydration payloads still introduce critical XSS.
Why AI coding tools introduce this vulnerability
AI tools building markdown rendering or rich text components routinely output <div dangerouslySetInnerHTML={{ __html: userContent }} /> without sanitizing the HTML with DOMPurify. They also render user links like <a href={userLink}>, allowing javascript:alert(1) payloads.
Technical Vulnerability Analysis
Cross-Site Scripting allows attackers to inject malicious JavaScript into victim browsers. In modern single-page applications, XSS can steal session tokens from localStorage/cookies, hijack the DOM to display fraudulent credential prompts, or execute transactions on behalf of the victim.
Remediation Playbook & Code Fixes
Why this fix works: Sanitize HTML with DOMPurify and strictly enforce http:// or https:// URL protocols.
Local CLI Verification Commands
Pre-Deployment Self-Audit Checklist
Knowledge Check: Verify Your Understanding
What is the primary architectural cause of stored & reflected cross-site scripting (xss) in modern react & next.js?
Test your website for ZX-XSS-001
Run our 14 deterministic engines to inspect your live deployment.