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

Tom Schuster · 2026年2月24日

AI 摘要 AI 生成,可能有误

Firefox 148 是首个发布标准化 Sanitizer API 的浏览器,该 API 让开发者能够对不受信任的 HTML 进行净化,以防止跨站脚本(XSS)攻击。通过使用新的 setHTML() 方法取代容易出错的 innerHTML 赋值,开发者可以默认获得安全保障,并自定义保留或移除哪些元素和属性。与 Trusted Types 结合使用时,该 API 可提供更强大的 XSS 防护,而无需专门的安全团队或大幅修改代码。

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.

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Mozilla Hacks

Intent to Ship: JPEG XL

AI 摘要Mozilla has announced its intent to ship JPEG XL support in Firefox, based on jxl-rs, a safe and compact Rust decoder built by Google Research after concerns about the attack surface of the original 100,000-line C++ implementation. Firefox's implementation includes progressive rendering, which lets images display as they download, a feature Safari's earlier version lacked. The article also compares JPEG XL with AVIF, noting that AVIF tends to produce smaller files at web quality, while JPEG XL excels at lossless imagery and recompressing existing JPEGs, so developers should choose based on their use case.

PACT: Anonymous Credentials for the Web

AI 摘要The article describes how websites' anti-bot defenses are increasingly failing, as browser privacy protections erase passive signals and generative AI renders CAPTCHAs ineffective, forcing users into a dilemma between privacy and access. It critiques device-attestation solutions like Google's Web Environment Integrity and Apple's Private Access Tokens for concentrating control in hardware manufacturers and threatening the open web's openness. As an alternative, Mozilla proposes a system of anonymous credentials built on Privacy Pass-style cryptography, where sites can rate-limit users anchored to scarce resources (such as email addresses or VPN subscriptions) without learning their identities, while open challenges like issuer blinding and issuer trust evaluation remain to be solved.

Announcing Web Serial Support in Firefox

AI 摘要Firefox 151 for Desktop now supports the Web Serial API, enabling web applications to communicate directly with serial-connected hardware such as microcontrollers, development boards, 3D printers, and power meters without native software. Mozilla collaborated with Adafruit to test the implementation against real hardware workflows, and security is handled through explicit per-site, per-port user permission prompts. Mozilla is also pursuing standardization of the API through the WHATWG.

Behind the Scenes Hardening Firefox with Claude Mythos Preview

AI 摘要Mozilla explains how it used Claude Mythos Preview and other AI models, driven by an agentic harness built atop its fuzzing infrastructure, to find and fix an unprecedented number of latent security bugs in Firefox, including sandbox escapes and bugs dating back 15-20 years, with 271 fixes shipped in Firefox 150. The team scaled the effort by parallelizing bug-hunting jobs across ephemeral VMs and integrating discovery into its full security bug lifecycle of deduplication, triage, and shipping fixes, noting that better models and harnessing techniques transformed AI bug reports from low-value noise into high-signal findings. Mozilla has published a sample of the bug reports, recommends that other software projects begin using these AI-assisted hardening techniques now, and plans to integrate this analysis into continuous integration to scan patches as they land.

Trustworthy JavaScript for the Open Web

AI 摘要Mozilla introduces WAICT (Web Application Integrity, Consistency and Transparency), a mechanism that cryptographically binds client-side web code to manifests committed to publicly auditable logs, protecting applications—even end-to-end encrypted ones—against malicious or compromised servers serving modified code. Sites can opt in to enforcement so browsers reject any code that has not been publicly logged, making attacks observable and attributable. An early prototype is available in Firefox Nightly and can be tested at waict.dev, with Mozilla collaborating with partners like Cloudflare, the Freedom of the Press Foundation, and Meta while developing the specifications openly.