Lion Cipher Lab

Eliminate DOM-based XSS with Trusted Types and a strict CSP

Why it matters

The beginner XSS lab teaches the defense that works when the malicious data passes through your server: encode it on the way out, lock down execution with a Content Security Policy, and reflected/stored XSS dies at the template. But there is an entire class of XSS that never gives your server the chance — DOM-based XSS. The payload lives in a URL fragment (`#...`), a query string read by JavaScript, a `postMessage`, or `window.name`; the browser never sends the fragment to the server at all, and your carefully-encoded server response is irrelevant because the danger happens AFTER the page…

What you'll learn

Steps in this lab

  1. Why server-side encoding can't touch this bug: DOM-based XSS
  2. Build the deliberately-vulnerable page and a header-setting local server
  3. Prove the DOM-XSS fires (and meet DevTools)
  4. Turn on Trusted Types and watch the sink throw a TypeError
  5. Write a named Trusted Types policy that sanitises with DOMPurify
  6. Lock down which policy NAMES are allowed with the trusted-types directive
  7. Roll out safely: Report-Only mode, a report endpoint, and enumerating every sink
  8. The judgment: when Trusted Types is right, when it isn't, and how a pro ships it

Open the full interactive lab →