---
title: "Goodbye innerHTML, Hello setHTML: Stronger XSS Protection in Firefox 148"
description: "Firefox 148 is the first browser to ship the standardized Sanitizer API, whose setHTML() method sanitizes untrusted HTML as it is inserted into the DOM, for example stripping an <img> with an onclick handler while keeping safe elements like <h1>."
url: "https://swe.quest/articles/goodbye-innerhtml-hello-sethtml-stronger-xss-protection-in-firefox-148-e1f8d6dcc75d2421"
canonical: "https://hacks.mozilla.org/2026/02/goodbye-innerhtml-hello-sethtml-stronger-xss-protection-in-firefox-148/"
source: "Mozilla Hacks"
published: "2026-02-24"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 2
tags: ["appsec","browsers","javascript"]
---

# Goodbye innerHTML, Hello setHTML: Stronger XSS Protection in Firefox 148

A post on [Mozilla Hacks](https://swe.quest/sources/mozilla-hacks.md), published 2026-02-24, 2 min read, Announcement. Original: [https://hacks.mozilla.org/2026/02/goodbye-innerhtml-hello-sethtml-stronger-xss-protection-in-firefox-148/](https://hacks.mozilla.org/2026/02/goodbye-innerhtml-hello-sethtml-stronger-xss-protection-in-firefox-148/)

## Summary

Firefox 148 is the first browser to ship the standardized Sanitizer API, whose setHTML() method sanitizes untrusted HTML as it is inserted into the DOM, for example stripping an \<img\> with an onclick handler while keeping safe elements like \<h1\>. Developers can replace error-prone innerHTML assignments with setHTML() with minimal code changes and supply a custom configuration of allowed or removed elements and attributes. Combined with Trusted Types, a strict policy can permit setHTML() while blocking other unsafe insertion sinks, offering XSS protection that is easier to adopt than Content-Security-Policy.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Application security](https://swe.quest/tags/appsec.md) (Security)
- [Browsers](https://swe.quest/tags/browsers.md) (Web & mobile)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)

## Prerequisites

- DOM manipulation
- cross-site scripting basics

## Keywords

Sanitizer API, setHTML, Trusted Types, Firefox 148, Content-Security-Policy, innerHTML

## Related posts

- [New WebKit Features in Safari 15.5](https://swe.quest/articles/new-webkit-features-in-safari-15-5-b4bbee299beae982.md): WebKit · 2022-05-16 · Easy · 5 min read · Browsers, CSS, Accessibility, Application security
  Safari 15.5 is mostly a polish and bug-fix release, adding three developer-facing technologies: the HTML \`inert\` attribute, which makes an element non-interactive and hides it from assistive technologies; the CSP Level 3 \`worker-src\` directive for restricting worker script sources; and WKWebView \`minimumViewportInset\`/\`maximumViewportInset\` APIs so apps can support the new CSS small, large and dynamic viewport units.
- [In March, we see Firefox 87](https://swe.quest/articles/in-march-we-see-firefox-87-89133003c9c65b13.md): Mozilla Hacks · 2021-03-23 · Medium · 4 min read · Browsers, Privacy, Developer tools, Accessibility
  Firefox 87 enables the beforeinput event and InputEvent.getTargetRanges() by default, letting web apps inspect and cancel text edits in inputs and contenteditable elements before the DOM changes, with an example that protects metadata spans inside an editable comment.
- [New to the web platform in July](https://swe.quest/articles/new-to-the-web-platform-in-july-fcd36ed79801648a.md): web.dev · 2026-07-31 · Easy · 4 min read · Browsers, CSS, Frontend
  Chrome 151, Firefox 153 and Safari 26.6 reached stable in July 2026.
- [New WebKit Features in Safari 15.4](https://swe.quest/articles/new-webkit-features-in-safari-15-4-378317c134d40474.md): WebKit · 2022-03-14 · Medium · 13 min read · Browsers, CSS, Frontend, JavaScript
  Safari 15.4 ships over 70 WebKit additions, led by the \<dialog\> element with ::backdrop, lazy-loaded images, the :has() parent selector (shipped first in Safari), Cascade Layers, CSS containment, and new small/large/dynamic viewport units (svh, lvh, dvh and friends) that fix mobile viewport sizing.
- [Declarative Shadow DOM](https://swe.quest/articles/declarative-shadow-dom-9810e27126b5f6c2.md): WebKit · 2023-02-13 · Medium · 3 min read · Browsers, Frontend
  Safari Technology Preview 162 enables declarative shadow DOM by default.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
