Cross-site scripting (XSS) is a web security vulnerability that allows attackers to inject malicious scripts into web pages viewed by other users. XSS attacks bypass the same-origin policy, enabling session hijacking, credential theft, keylogging, and browser exploitation. This guide covers reflected, stored, and DOM-based XSS with real-world payloads and filter bypass techniques.
Types of Cross-Site Scripting (XSS)
XSS attacks come in three forms: reflected XSS (payload reflected in immediate response), stored XSS (payload persisted in the database and served to all users), and DOM-based XSS (client-side JavaScript processes attacker-controlled data without server involvement).
Reflected XSS: Detection & Exploitation
">
'>
Stored XSS: Persistent Impact
Stored XSS is the most dangerous type — the payload is stored server-side and executes every time a user visits the affected page. Common injection points: comment fields, user profiles, product reviews, forum posts.
DOM-Based XSS
DOM XSS occurs when JavaScript reads from an attacker-controlled source (like location.hash or URL parameters) and passes it to a dangerous sink (like innerHTML or eval) without sanitization.
// Vulnerable JavaScript pattern
document.getElementById('output').innerHTML = location.hash.slice(1);
// Attack URL
https://target.com/page#
// Common sources
location.href, location.search, location.hash, document.referrer, window.name
// Common sinks
innerHTML, outerHTML, document.write, eval, setTimeout, setInterval, src attributeXSS Filter Bypass Techniques
<script>alert(1)</script>
click
jaVasCript:/*-/*`/*\`/*'/*"/**/(/* */oNcliCk=alert() )//%0D%0A%0d%0a//\x3csVg/References
See OWASP Cross-Site Scripting (XSS) and PortSwigger XSS Cheat Sheet.