Cross-Site Scripting (XSS) is a vulnerability that allows an attacker to inject malicious client-side scripts into web pages viewed by other users. It appears in three primary forms: reflected, stored, and DOM-based.
Each lab below contains a deliberately vulnerable input. Try injecting JavaScript payloads and observe the results. Example payloads are provided to guide your exploration.
The malicious script is part of the request and is reflected by the response without proper encoding. It executes immediately in the victim's browser when the page loads.
innerHTML, so the browser parses it as HTML. Note that
<script> inserted via innerHTML does not execute โ
event handlers like onerror and onload do.Malicious input is saved on the server (database, comment field, profile) and later displayed to other users without sanitization. Every visitor who loads the affected page executes the payload.
localStorage (simulating a database) and rendered with
innerHTML on every load. A payload posted once persists and executes
for every subsequent visit.The vulnerability lives entirely in client-side JavaScript. The server response is
identical to the original HTML โ the code reads data from a controllable source
(location.hash, document.referrer) and writes it to a dangerous
sink (innerHTML) without sanitization.
location.hash
innerHTMLlocation.hash and assigns it to innerHTML. The payload
never reaches the server โ it's purely client-side DOM manipulation. Fixing this
requires textContent or a sanitizer like DOMPurify.