1 How XSS Works
Cross-Site Scripting (XSS) allows attackers to inject malicious JavaScript into pages viewed by other users. The browser executes this script in the context of the victim's session — enabling cookie theft, keylogging, or redirects.
Reflected XSS — the payload is in the URL/request and reflected back immediately:
<!-- URL: /search?q=<script>alert(document.cookie)</script> -->
<p>Results for: <?= $_GET['q'] ?></p>
Stored XSS — the payload is saved to the database and rendered for every visitor. More dangerous because it's persistent and affects all users who view that content.