Lion Cipher Lab

Stop XSS with output encoding and a Content Security Policy

Why it matters

Cross-site scripting is one of the most common and most persistent web vulnerabilities on earth, and almost every real instance of it comes down to the same root cause: someone rendered user-controlled text as if it were trusted markup. Reading that sentence is not the same as feeling it. In this lab you build a tiny web app that has the bug on purpose, then watch three different flavors of XSS — reflected, stored, and DOM-based — actually fire in your own browser using harmless marker payloads. Then you fix each one the right way and watch the fix hold. The reason this matters more than a…

What you'll learn

Steps in this lab

  1. The words first: XSS, the three types, the DOM, context, encoding
  2. Set up: Python, Flask, and a folder
  3. Build the VULNERABLE app (the bugs, on purpose)
  4. Prove #1 — reflected XSS fires from the URL
  5. Prove #2 — stored XSS fires for every viewer
  6. Prove #3 — DOM-based XSS fires without the server
  7. FIX #1 — contextual output encoding (the primary defense)
  8. FIX #2 — DOM-based XSS needs a safe SINK, not a server fix
  9. FIX #3 — a Content Security Policy as defense in depth
  10. Cookie hardening — shrink the blast radius (it does not prevent XSS)
  11. Judgment: the hierarchy, the footguns, and how a pro ships

Open the full interactive lab →