EXERCISE 1 — Sanitizing a rich-text comment with DOMPurify =========================================================== GOAL: allow , , only; strip everything else. const clean = DOMPurify.sanitize(dirty, { ALLOWED_TAGS: ["b", "i", "a"], ALLOWED_ATTR: ["href"], }); element.innerHTML = clean; // safe to insert INPUT (dirty): hi OUTPUT (clean): hi -> the hi is on the allowlist, so it's KEPT and renders bold. -> the is NOT on the allowlist, so the whole element (and its onerror handler) is DROPPED. Nothing executes. Other examples of what gets removed by this config: -> removed entirely x -> the javascript: URL is stripped (DOMPurify blocks dangerous URL schemes; the may remain without the unsafe href) x -> kept, the onclick attribute dropped (onclick isn't in ALLOWED_ATTR, and handlers are blocked) WHY ALLOWLISTING (NOT BLOCKLISTING) MAKES IT SAFE: - DOMPurify PARSES the input into a real DOM and then KEEPS ONLY the elements/attributes you explicitly permitted, discarding everything else BY DEFAULT. The decision is "is this on the safe list?" -- anything not on it (known or unknown, today or invented tomorrow) is removed. - A blocklist would instead try to ENUMERATE bad things to strip (