Lion Cipher Lab

Defend a web app against DOM clobbering

Why it matters

Teams ship a strict Content Security Policy, watch script-src block classic cross-site scripting, and conclude the client is safe. It is not. DOM clobbering injects only benign markup — plain id and name attributes on ordinary tags — and no script ever runs, so script-src is irrelevant. Yet those attributes can overwrite the global variables and object properties your JavaScript reads, silently redirecting a fetch, disabling a check, or even breaking the sanitizer that was supposed to protect you. If your mental model of client-side risk stops at 'no XSS because CSP,' this is the gap an…

What you'll learn

Steps in this lab

  1. The three words you need first: DOM, global object, named access
  2. Build a tiny, safe target on your own machine
  3. See a single element become a global — the core mechanic
  4. Clobber a nested property: the id + name HTMLCollection trick
  5. Why a strict CSP does not stop this
  6. Defenses that feel right but fail
  7. Fix #1 — don't let security-relevant values live on window/document
  8. Fix #2 — sanitize untrusted markup with a clobbering-aware sanitizer (DOMPurify)
  9. Named failure modes — how the fix gets un-fixed
  10. The judgment to carry out of here

Open the full interactive lab →