โš ๏ธ
Educational environment. This lab intentionally demonstrates Cross-Site Scripting vulnerabilities. All demos run entirely in your browser and are designed for learning purposes only.

Interactive Cross-Site Scripting Laboratory

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.

LAB 01

Reflected XSS

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.

search.php?q=...
Vulnerable output innerHTML
Results will appear here...
Safe output textContent
Escaped result...
Try: <img src=x onerror=alert(1)> <svg onload=alert(1)> <b>Bold text</b> <script>alert(1)</script>
๐Ÿ’ก Why it works: the vulnerable output assigns input to innerHTML, so the browser parses it as HTML. Note that <script> inserted via innerHTML does not execute โ€” event handlers like onerror and onload do.
LAB 02

Stored XSS

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.

comments.php
Comments (rendered with innerHTML)
No comments yet. Be the first!
Try in the comment: <img src=x onerror=alert(document.domain)> <svg/onload=alert(1)> <details open ontoggle=alert(1)>
๐Ÿ’ก Why it works: comments are stored in localStorage (simulating a database) and rendered with innerHTML on every load. A payload posted once persists and executes for every subsequent visit.
LAB 03

DOM-based XSS

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.

greeting.html#...
Rendered from location.hash innerHTML
Hello, World
Try: <img src=x onerror=alert(1)> <iframe src=javascript:alert(1)> <svg onload=alert(document.cookie)>
๐Ÿ’ก Why it works: the page reads location.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.