惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
有赞技术团队
有赞技术团队
博客园_首页
H
Help Net Security
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
V
Visual Studio Blog
The Cloudflare Blog
腾讯CDC
Jina AI
Jina AI
Last Week in AI
Last Week in AI
月光博客
月光博客
博客园 - 叶小钗
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Blog — PlanetScale
Blog — PlanetScale
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
爱范儿
爱范儿
N
Netflix TechBlog - Medium
F
Fortinet All Blogs

Mozilla Hacks – the Web developer blog

Intent to Ship: JPEG XL – Mozilla Hacks - the Web developer blog PACT: Anonymous Credentials for the Web – Mozilla Hacks - the Web developer blog Announcing Web Serial Support in Firefox – Mozilla Hacks - the Web developer blog Behind the Scenes Hardening Firefox with Claude Mythos Preview – Mozilla Hacks - the Web developer blog Trustworthy JavaScript for the Open Web – Mozilla Hacks - the Web developer blog Firefox Developer Edition and Beta: Try out Mozilla’s .rpm package! – Mozilla Hacks - the Web developer blog Why is WebAssembly a second-class language on the web? – Mozilla Hacks - the Web developer blog Launching Interop 2026 – Mozilla Hacks - the Web developer blog CRLite: Fast, private, and comprehensive certificate revocation checking in Firefox – Mozilla Hacks - the Web developer blog Improving Firefox Stability in the Enterprise by Reducing DLL Injection – Mozilla Hacks - the Web developer blog Launching Interop 2025 – Mozilla Hacks - the Web developer blog Introducing Uniffi for React Native: Rust-Powered Turbo Modules – Mozilla Hacks - the Web developer blog Llamafile v0.8.14: a new UI, performance gains, and more – Mozilla Hacks - the Web developer blog 0Din: A GenAI Bug Bounty Program – Securing Tomorrow’s AI Together – Mozilla Hacks - the Web developer blog Announcing Official Puppeteer Support for Firefox – Mozilla Hacks - the Web developer blog Snapshots for IPC Fuzzing – Mozilla Hacks - the Web developer blog Sponsoring sqlite-vec to enable more powerful Local AI applications – Mozilla Hacks - the Web developer blog Experimenting with local alt text generation in Firefox Nightly – Mozilla Hacks - the Web developer blog Llamafile’s progress, four months in – Mozilla Hacks - the Web developer blog Porting a cross-platform GUI application to Rust – Mozilla Hacks - the Web developer blog
Goodbye innerHTML, Hello setHTML: Stronger XSS Protection...
https://frederikbraun.de · 2026-02-24 · via Mozilla Hacks – the Web developer blog

Cross-site scripting (XSS) remains one of the most prevalent vulnerabilities on the web. The new standardized Sanitizer API provides a straightforward way for web developers to sanitize untrusted HTML before inserting it into the DOM. Firefox 148 is the first browser to ship this standardized security enhancing API, advancing a safer web for everyone. We expect other browsers to follow soon.

An XSS vulnerability arises when a website inadvertently lets attackers inject arbitrary HTML or JavaScript through user-generated content. With this attack, an attacker could monitor and manipulate user interactions and continually steal user data for as long as the vulnerability remains exploitable. XSS has a long history of being notoriously difficult to prevent and has ranked among the top three web vulnerabilities (CWE-79) for nearly a decade.

Firefox has been deeply involved in solutions for XSS from the beginning, starting with spearheading the Content-Security-Policy (CSP) standard in 2009. CSP allows websites to restrict which resources (scripts, styles, images, etc.) the browser can load and execute, providing a strong line of defense against XSS. Despite a steady stream of improvements and ongoing maintenance, CSP did not gain sufficient adoption to protect the long tail of the web as it requires significant architectural changes for existing web sites and continuous review by security experts.

The Sanitizer API is designed to help fill that gap by providing a standardized way to turn malicious HTML into harmless HTML — in other words, to sanitize it. The setHTML( ) method integrates sanitization directly into HTML insertion, providing safety by default. Here is an example of sanitizing a simple unsafe HTML:

document.body.setHTML(`<h1>Hello my name is <img src="x" 
onclick="alert('XSS')">`);

This sanitization will allow the HTML <h1> element while removing the embedded <img> element and its onclick attribute, thereby eliminating the XSS attack resulting in the following safe HTML:

<h1>Hello my name is</h1>

Developers can opt into stronger XSS protections with minimal code changes by replacing error-prone innerHTML assignments with setHTML(). If the default configuration of setHTML( ) is too strict (or not strict enough) for a given use case, developers can provide a custom configuration that defines which HTML elements and attributes should be kept or removed. To experiment with the Sanitizer API before introducing it on a web page, we recommend exploring the Sanitizer API playground.

For even stronger protections, the Sanitizer API can be combined with Trusted Types, which centralize control over HTML parsing and injection. Once setHTML( ) is adopted, sites can enable Trusted Types enforcement more easily, often without requiring complex custom policies. A strict policy can allow setHTML( ) while blocking other unsafe HTML insertion methods, helping prevent future XSS regressions.

The Sanitizer API enables an easy replacement of innerHTML assignments with setHTML( ) in existing code, introducing a new safer default to protect users from XSS attacks on the web. Firefox 148 supports the Sanitizer API as well as Trusted Types, which creates a safer web experience. Adopting these standards will allow all developers to prevent XSS without the need for a dedicated security team or significant implementation changes.


Image credits for the illustration above: Website, by Desi Ratna; Person, by Made by Made; Hacker by Andy Horvath.

More articles by Tom Schuster…

Frederik Braun manages the Firefox Application Security team. He builds security for the web and for Mozilla Firefox from Berlin. As a contributor to standards, Frederik is also improving the web platform by bringing security into the defaults with specifications like the Sanitizer API and Subresource Integrity. When not at work, Frederik likes reading a good novel or going on long bike treks across Europe.

More articles by Frederik Braun…

Christoph has over two decades of experience in software engineering and computer security. His expertise includes designing secure systems with fail-safe defaults, mitigating cross-site scripting vulnerabilities, preventing machine-in-the-middle attacks, and advancing security foundations for trustworthy AI systems. He earned his Ph.D. in Computer Science from the University of California, Irvine, where his research focused on information flow tracking techniques in web browsers.

More articles by Christoph Kerschbaumer…