704: Sanitizer API with Frederik Braun
Episode
62 min
Read time
2 min
Topics
Leadership, Design & UX, Software Development
AI-Generated Summary
Key Takeaways
- ✓setHTML as innerHTML replacement: Replace `element.innerHTML` with `element.setHTML(input)` to get browser-guaranteed XSS-safe HTML insertion. The method uses the browser's own HTML parser, so sanitization stays current as HTML evolves. No configuration required for basic usage — the default safe list handles common elements automatically, making it a near-direct search-and-replace upgrade with zero security expertise needed.
- ✓setHTML vs setHTMLUnsafe: Two methods exist by design. `setHTML` cannot be configured to allow scripts under any circumstance — XSS safety is guaranteed. `setHTMLUnsafe` mirrors React's "dangerously set inner HTML" naming pattern, signaling developer intent. Frederik Braun recommends only using the unsafe variant if a security engineer is actively involved in reviewing the configuration and its implications.
- ✓Allowlist configuration over blocklist: Rather than removing unwanted elements, configure a `new Sanitizer()` with an explicit `elements` array listing only what your use case requires — paragraph, anchor, bold, italic, blockquote, lists. This approach stays evergreen: future HTML elements are automatically excluded. Custom web components with dash-separated names like `dave-card` can be explicitly added to the allowlist by name.
- ✓Defense-in-depth with server-side sanitization: Server-side sanitization and `setHTML` serve complementary roles. Backend libraries sanitize on intake, but browser-side sanitization handles mismatches between server assumptions and the specific browser rendering the page. Academic research confirms that sanitizers outside the browser frequently fail on edge cases — malformed HTML, browser-specific parsing quirks, and newly introduced elements that backend libraries haven't yet catalogued.
- ✓CSP + Trusted Types integration: Content Security Policy's Trusted Types feature can be set to reject all `innerHTML`, `document.write`, `outerHTML`, and `insertAdjacentHTML` calls at runtime via a single HTTP header configuration. Combined with `setHTML`, this creates a hard enforcement layer where unsafe DOM manipulation throws errors rather than silently executing. Despite CSP existing since roughly 2010, over 80% of pages using it still lack sufficient XSS protection.
What It Covers
Frederik Braun, manager of Firefox application security at Mozilla, explains the newly shipped Sanitizer API — a browser-native solution to cross-site scripting (XSS). The episode covers `setHTML` vs `innerHTML`, sanitizer configuration with allowlists, integration with Content Security Policy, DOMPurify's role, and how the API handles custom elements and data attributes.
Key Questions Answered
- •setHTML as innerHTML replacement: Replace `element.innerHTML` with `element.setHTML(input)` to get browser-guaranteed XSS-safe HTML insertion. The method uses the browser's own HTML parser, so sanitization stays current as HTML evolves. No configuration required for basic usage — the default safe list handles common elements automatically, making it a near-direct search-and-replace upgrade with zero security expertise needed.
- •setHTML vs setHTMLUnsafe: Two methods exist by design. `setHTML` cannot be configured to allow scripts under any circumstance — XSS safety is guaranteed. `setHTMLUnsafe` mirrors React's "dangerously set inner HTML" naming pattern, signaling developer intent. Frederik Braun recommends only using the unsafe variant if a security engineer is actively involved in reviewing the configuration and its implications.
- •Allowlist configuration over blocklist: Rather than removing unwanted elements, configure a `new Sanitizer()` with an explicit `elements` array listing only what your use case requires — paragraph, anchor, bold, italic, blockquote, lists. This approach stays evergreen: future HTML elements are automatically excluded. Custom web components with dash-separated names like `dave-card` can be explicitly added to the allowlist by name.
- •Defense-in-depth with server-side sanitization: Server-side sanitization and `setHTML` serve complementary roles. Backend libraries sanitize on intake, but browser-side sanitization handles mismatches between server assumptions and the specific browser rendering the page. Academic research confirms that sanitizers outside the browser frequently fail on edge cases — malformed HTML, browser-specific parsing quirks, and newly introduced elements that backend libraries haven't yet catalogued.
- •CSP + Trusted Types integration: Content Security Policy's Trusted Types feature can be set to reject all `innerHTML`, `document.write`, `outerHTML`, and `insertAdjacentHTML` calls at runtime via a single HTTP header configuration. Combined with `setHTML`, this creates a hard enforcement layer where unsafe DOM manipulation throws errors rather than silently executing. Despite CSP existing since roughly 2010, over 80% of pages using it still lack sufficient XSS protection.
- •DOMPurify as the current fallback: For browsers not yet supporting the Sanitizer API, DOMPurify remains the recommended library — its author Mario Heiderich co-authored the Sanitizer API specification. DOMPurify weighs approximately 8.3KB gzipped. The progressive enhancement pattern is: check `if (window.Sanitizer)`, use `setHTML` if available, otherwise fall back to DOMPurify plus `innerHTML`. Firefox shipped the API first; Chrome support was imminent at recording time.
Notable Moment
Frederik Braun notes that cross-site scripting remains one of the top three most reported vulnerabilities in the US National Vulnerability Database — despite Content Security Policy existing for roughly fifteen years. The implication is that technically sound solutions fail without adoption simplicity, which is precisely the problem `setHTML` is designed to solve.
You just read a 3-minute summary of a 59-minute episode.
Get Shop Talk Show summarized like this every Monday — plus up to 2 more podcasts, free.
Pick Your Podcasts — FreeKeep Reading
More from Shop Talk Show
718: 3D Printing Life Upgrades, Don’t Give Away Your Dopamine, and CodePen App Deploys
Jun 8 · 58 min
The Product Experience
Lessons from Firefox and Twitter - Alan Byrne (Product Leader, Mozilla)
Feb 18
More from Shop Talk Show
717: Better DX for Web Components, What Was Popular That Now We’re Used To?
Jun 1 · 53 min
Eye on AI
#319 Subho Halder: Why Traditional App Security Fails in the Age of AI
Feb 1
Books, tools, and gear mentioned in this episode
SignalCast may earn commission on purchases via these links. As an Amazon Associate, SignalCast earns from qualifying purchases.
Tools
“Content Security Policy's Trusted Types feature can be set to reject all `innerHTML`, `document.write`, `outerHTML`, and `insertAdjacentHTML` calls at runtime via a single HTTP header configuration.”
- Sanitizer APIRecommended
“Frederik Braun, manager of Firefox application security at Mozilla, explains the newly shipped Sanitizer API — a browser-native solution to cross-site scripting (XSS).”
- DOMPurifyRecommended
by Mario Heiderich
“For browsers not yet supporting the Sanitizer API, DOMPurify remains the recommended library — its author Mario Heiderich co-authored the Sanitizer API specification. DOMPurify weighs approximately 8.3KB gzipped.”
More from Shop Talk Show
We summarize every new episode. Want them in your inbox?
718: 3D Printing Life Upgrades, Don’t Give Away Your Dopamine, and CodePen App Deploys
717: Better DX for Web Components, What Was Popular That Now We’re Used To?
716: Google I/O 2026 Recap Edition
715: Would You Like a LLM With Your Browser?
714: Camping, Burnout, and Chris’ CSS Talk
Similar Episodes
Related episodes from other podcasts
The Product Experience
Feb 18
Lessons from Firefox and Twitter - Alan Byrne (Product Leader, Mozilla)
Eye on AI
Feb 1
#319 Subho Halder: Why Traditional App Security Fails in the Age of AI
Cognitive Revolution
Jan 25
The Internet Computer: Caffeine.ai CEO Dominic Williams on Unstoppable, Self-Writing Software
The Rework Podcast
Jan 21
AI Revisited
No Priors: Artificial Intelligence | Technology | Startups
May 28
Building an AI Guardian for Enterprise with Onyx Security CEO Maxim Bar Kogan
Explore Related Topics
This podcast is featured in Best Cybersecurity Podcasts (2026) — ranked and reviewed with AI summaries.
Read this week's Software Engineering Podcast Insights — cross-podcast analysis updated weekly.
You're clearly into Shop Talk Show.
Every Monday, we deliver AI summaries of the latest episodes from Shop Talk Show and 192+ other podcasts. Free for up to 3 shows.
Start My Monday DigestNo credit card · Unsubscribe anytime