XSS Playground
Cross-Site Scripting — inject HTML/JavaScript and see the difference between unsafe innerHTML and sanitized rendering.
Quick Payloads — click to load
✗ Vulnerable
// Directly sets HTML — dangerous! element.innerHTML = userInput; // Any <script> or onerror= // will execute immediately
✓ Fixed
// Treats input as text only element.textContent = userInput; // Or with DOMPurify for rich text: element.innerHTML = DOMPurify.sanitize(userInput);
XSS occurs when user input is rendered as HTML instead of text. The browser parses embedded scripts and executes them — giving attackers full JavaScript access to the page.
innerHTML tells the browser to parse the string as HTML — including <script> tags and event handlers like onerror. Any injected JS runs with full access to your cookies, localStorage, and DOM.
Use textContent instead of innerHTML for user input. For rich text, use DOMPurify to sanitize. Add a Content-Security-Policy header to restrict which scripts can execute.
XSS caused the 2005 MySpace Samy worm (1M accounts in 20h), the 2018 British Airways breach (500K payment cards stolen), and is listed in the OWASP Top 10 every year since 2003.
Monitoring runtime activity… waiting for events
Stream will begin shortly