Lion Cipher Lab

Lock down XSS with a strict nonce-based Content-Security-Policy

Why it matters

Almost every team that adds a Content-Security-Policy adds one that does nothing. They reach for a policy that includes 'unsafe-inline' -- because removing it breaks the site's inline scripts -- and 'unsafe-inline' is precisely the thing that lets an attacker's injected inline script run. So the header is present, the security scanner is happy, and the XSS still fires. A CSP that actually stops cross-site scripting looks different: it trusts scripts by an unguessable per-request nonce, not by where they come from, and it forbids the inline execution an attacker relies on. Google's own…

What you'll learn

Steps in this lab

  1. What a CSP is, and the trap almost everyone falls into
  2. Set up the lab app
  3. Start the beacon listener (your measurement instrument)
  4. BEFORE — build the app with no CSP and watch the beacon fire
  5. The strict policy, explained before you apply it
  6. ROLL OUT SAFELY — report-only first, with a collector
  7. AFTER — enforce, and measure the beacon go to zero
  8. Refactor the things a strict CSP breaks
  9. The honest limits — where a CSP still won't save you

Open the full interactive lab →