exercises / find-your-first-xss
Find Your First XSS
A guided walkthrough to land your first cross-site scripting payload, step by step.
Cross-site scripting (XSS) happens when an application takes input from one person and shows it to another without neutralizing it, so your input runs as script in someone else's browser. This exercise walks you through finding one for the first time. Open the XSS Playground in another tab and follow along.
Step 1 — Find where your input comes back
XSS lives wherever something you type is later displayed. In the playground, that's the guestbook: you post a message, and it appears on the page. Post a plain, harmless message first and confirm it shows up. This is your input reflecting back — the precondition for XSS.
Step 2 — Test whether HTML is interpreted
Now ask the key question: is your input treated as text, or as HTML? Post a simple tag:
<b>hello</b>
If the word "hello" appears bold, the app is rendering your input as HTML — a strong signal it might also run script. If you literally see the <b> characters, the app is escaping output (good for them, harder for you).
Step 3 — Escalate from formatting to script
Bold text is harmless; the goal is to prove you can run code. The classic proof is to make the page execute JavaScript. Try an element that runs script through an event handler rather than a bare <script> tag (which often won't run when inserted dynamically):
<img src=x onerror="alert(document.domain)">
The image fails to load on purpose, which fires the onerror handler, which runs your script. If a dialog appears, you've executed code in the page's context. That's XSS.
Step 4 — Understand the impact
alert(1) is just a proof. The reason XSS is dangerous is that your script runs with the victim's session: it could read their cookies, act as them, or rewrite the page to phish them. In the lab, capturing the flag stands in for "the attacker's payload ran".
Step 5 — Now fix it in your head
For every bug you find, practice the fix. XSS is prevented by encoding output for its context (so < becomes < and never starts a tag) and, for rich content, allow-listing safe HTML. Notice that the rest of this site escapes everything you submit — that's the defense, applied.
What you just learned
You found where input reflects, tested whether it's interpreted as HTML, and escalated to running script — the exact loop you'll repeat on every target. Capture the flag in the XSS Playground, then come back and try it without the hints.