MXSS in 2021 - One Long Solved Problem?
Dr.-Ing. Mario Heiderich (Head · Cure53)
Swiss Cyber Storm 2021 · Day 1 · Scenario_2
Overview
In this insightful and technically dense presentation at Swiss Cyber Storm, Dr.-Ing. Mario Heiderich, Head of the penetration testing company Cure53 and maintainer of the widely used DOMPurify library, dissects the persistent and often misunderstood vulnerability class known as Mutation Cross-Site Scripting (MXSS). While Cross-Site Scripting (XSS) is frequently considered a "solved problem" by many developers, Heiderich demonstrates how MXSS represents a sophisticated evolution, bypassing even robust sanitization efforts through the intricate and sometimes unpredictable parsing behaviors of modern web browsers.

Key moments
- 1:00 What is Cross-Site Scripting (XSS)?
- 5:50 Introduction to Mutation XSS (MXSS) and browser optimization
- 11:00 How MXSS bypasses server-side sanitization in webmailers
- 15:00 The 'Noscript' MXSS bypass that affected Google
- 18:40 Root causes of MXSS: browser context switching
- 23:00 The strategic solution: changing the HTML standard
- 26:00 Browser implementation of the new Sanitizer API
- 29:00 The origin story of MXSS research (Q&A)
MXSS in 2021 - One Long Solved Problem?
Speakers: Dr.-Ing. Mario Heiderich, Head, Cure53
Conference: Swiss Cyber Storm
YouTube: https://www.youtube.com/watch?v=MXEowmgwiSg
Overview
In this insightful and technically dense presentation at Swiss Cyber Storm, Dr.-Ing. Mario Heiderich, Head of the penetration testing company Cure53 and maintainer of the widely used DOMPurify library, dissects the persistent and often misunderstood vulnerability class known as Mutation Cross-Site Scripting (MXSS). While Cross-Site Scripting (XSS) is frequently considered a "solved problem" by many developers, Heiderich demonstrates how MXSS represents a sophisticated evolution, bypassing even robust sanitization efforts through the intricate and sometimes unpredictable parsing behaviors of modern web browsers.
Heiderich, who initially discovered and named MXSS, eloquently details its origins, evolution through three distinct generations, and the profound challenges it poses to web application security. The talk culminates in a strategic vision for a more secure web: the standardization and browser-native implementation of HTML sanitization. This shift aims to move the burden of complex, context-dependent sanitization away from individual JavaScript libraries and into the core of web browsers, promising a fundamental change to how HTML is handled and secured.
The significance of this talk extends beyond mere vulnerability disclosure. It highlights a critical architectural flaw in how web applications interact with browser rendering engines, particularly when dealing with untrusted HTML content. Heiderich’s journey from discovering MXSS to lobbying for a global standard underscores the immense effort required to address deep-seated security challenges and the impact of dedicated research on the future of web security.
Background
▶ Watch: What is Cross-Site Scripting (XSS)? (1:00)
To understand Mutation XSS, it's essential to first grasp the fundamentals of traditional Cross-Site Scripting (XSS). As Heiderich explains, XSS is fundamentally about an attacker modifying a website through the injection of arbitrary HTML and JavaScript. While technically misnamed – as it's not truly "scripting across sites" but rather injecting code into a trusted domain to attack its users – XSS remains a potent threat. It transforms a vulnerable website into an "accomplice," leveraging its trust to execute malicious code in the context of other users' browsers. This can lead to a wide array of devastating consequences, including stealing credentials (even from password managers), redirecting forms, siphoning anti-CSRF tokens, installing cryptocurrency miners, registering service workers, or even activating a user's camera and microphone, as demonstrated with a hypothetical attack on meet.google.com.
Defending against XSS traditionally involves a multi-pronged approach:
- Avoiding user-controlled data echo: Never directly reflect user input without proper processing.
- Filtering and sanitization: Scrutinizing and cleaning user-supplied data to remove malicious constructs.
- Context awareness: Understanding the over 24 different contexts (HTML, JavaScript, SVG, CSS, comments, attributes, etc.) where injections can occur and applying appropriate encoding or escaping.
- Secure configurations: Implementing robust HTTP headers (like Content Security Policy or CSP), configuring secure cookies, and generally exercising extreme caution with DOM manipulations.
However, Heiderich reveals a critical flaw in this conventional wisdom: even when developers meticulously follow all best practices—encoding, escaping, filtering, and sanitizing everything "by the book"—a potential for script injection can still persist. This is the realm of MXSS. The problem arises because web browsers, for reasons of performance, convenience, and fault tolerance, perform extensive optimizations and "fixes" on incoming HTML. If a browser receives malformed or ambiguous HTML, it attempts to repair it before rendering. While often beneficial, this auto-correction can inadvertently transform seemingly safe, sanitized markup into dangerous, executable code, creating a "hidden attack surface" that traditional sanitizers cannot foresee or prevent.
A prime example of an application highly susceptible to MXSS is a webmailer. These applications handle incredibly sensitive data (emails, contacts, password reset tokens) from arbitrary, untrusted sources. They must parse complex HTML emails, often with varying character sets and attachments, all while maintaining speed, accessibility, and rich functionality (e.g., rich text editors). The immense complexity and the need to render untrusted HTML make webmailers notoriously difficult to secure. Typically, server-side sanitization is employed, where email content is cleaned before being sent to the browser. However, as Heiderich demonstrates, this server-side "safety" can be undone by the browser's aggressive parsing, leading to a situation where the server believes the content is safe, but the browser, after its optimizations, executes attacker-controlled JavaScript.
Key Findings
▶ Watch: How MXSS bypasses server-side sanitization in webmailers (11:00)
The core discovery presented is that Mutation XSS (MXSS) exploits the discrepancy between what a sanitizer considers safe HTML and how a browser's parser ultimately interprets and renders that HTML. The browser's internal optimization processes, designed to fix broken markup and ensure rapid rendering, can inadvertently "mutate" safe content into an unsafe, executable form. Heiderich categorizes MXSS into three distinct generations, each leveraging increasingly sophisticated browser parsing quirks:
- First Generation MXSS (2012-2013): Primarily affecting older browsers like Internet Explorer and Firefox, these early vectors focused on manipulating attribute contents. Attackers crafted seemingly innocuous HTML that, once parsed by the browser, would have its attributes rearranged or interpreted in a way that led to XSS. The speaker noted that while these were foundational, a thorough demo was not feasible due to time constraints, but examples were available in the talk's slides.
- Second Generation MXSS: This generation demonstrated a more alarming capability: producing entirely new, malicious markup "out of thin air." Heiderich provided a compelling live example during the talk, showcasing how a specific input like
<input article xmlns:a="b">containing some content within an XML namespace could lead the browser to construct a "massive contraption" of HTML. This unexpected generation of markup could, under the right circumstances, result in XSS. This highlighted that browsers weren't just fixing existing markup but actively creating new structures based on their interpretation of ambiguous input.
- Third Generation MXSS (Discovered ~2019): This is described as "badass stuff" that directly impacted modern sanitizers, including Heiderich's own DOMPurify. Initially, a bypass was found that required a specific, uncommon configuration option (allowing
noscriptelements), leading Heiderich to initially downplay its severity. However, further research revealed its true danger. This generation of attacks leverages two major root causes:
- Predictable Changes in Markup Type Force a Change of Parser: This involves crafting HTML that intentionally confuses the browser's parser by switching between different markup contexts (e.g., XML, SVG, MathML, and HTML). By transitioning between these contexts, an attacker can trick the browser into interpreting an otherwise harmless element (like a
styletag) in an unsafe HTML context, thereby freeing embedded JavaScript. - Unpredictable Changes in Markup Type Force a Change of Parser: This more insidious variant occurs when a sanitizer removes a seemingly problematic element, but the remaining, "cleaned" markup then causes the browser to switch parsing contexts in an unexpected way. This change in context can activate malicious code that the sanitizer, operating under a different parsing assumption, believed was safely inert. The sanitizer cannot predict the future state of the DOM after its modifications, making this particularly challenging to mitigate.
These key findings underscore that MXSS is not just about poorly written sanitizers, but a fundamental challenge in the interaction between untrusted input, browser parsing heuristics, and the dynamic nature of the DOM.
Technical Deep Dive
▶ Watch: Root causes of MXSS: browser context switching (18:40)
The third generation of MXSS attacks, particularly those affecting DOMPurify and even Google's own sanitizer, exemplify the sophistication and danger of this vulnerability class. Heiderich detailed a critical attack vector involving the <noscript> element. The attack vector looks like this:
Here's a breakdown of how it works:
- Sanitizer's Perspective (JavaScript Off): A sanitizer, like DOMPurify, typically operates within an internal DOM where JavaScript is disabled. In this environment, it encounters the
<noscript>tag and, assuming JavaScript is off, parses its content. It sees the closing</noscript>tag within theattributevalue of the<p>element. The sanitizer's logic is designed to remove the entire<noscript>element and its potentially dangerous content. After sanitization, the output would appear safe, as the<noscript>tag and its embedded XSS payload would be removed. - Browser's Perspective (JavaScript On): When this "sanitized" markup is then rendered in a user's browser, JavaScript is typically enabled. Modern browsers, when JavaScript is active, simply ignore the entire content of a
<noscript>element. They don't parse it. Instead, they look for the actual closing</noscript>tag. In the crafted payload, the</noscript>inside theattributestring effectively closes the outer<noscript>element prematurely from the browser's perspective. What follows,<img src=x onerror=alert(1)>, is then parsed as a regular HTML element outside the<noscript>context. This image tag, with itsonerrorevent handler, executes thealert(1)JavaScript, leading to XSS.
This specific vector was famously discovered by Masato Kinugawa on Google's index page, which, surprisingly, was found to be using innerHTML for displaying content. This revelation led to a significant bounty and highlighted that even security-conscious organizations could fall victim to MXSS if their sanitization logic didn't account for these browser parsing discrepancies.
Heiderich further elaborated on the two root causes identified for Gen 3 MXSS, focusing on how browser context switching facilitates these attacks:
Root Cause 1: Predictable Changes in Markup Type
This involves an attacker deliberately crafting HTML that forces the browser to switch between different parsing contexts in a predictable manner, leading to an XSS. An example involves embedding HTML elements within an SVG (Scalable Vector Graphics) context:
Here's the mutation:
- The browser starts parsing in an SVG context.
- It encounters a broken
pelement (e.g.,</p>or evenpwithout a closing tag). Crucially, the browser, in its effort to "repair" broken HTML, often closes open tags or even opens missing tags. - This "repaired" HTML
pelement is an HTML element, not an SVG element. This forces a context switch from SVG parsing to HTML parsing. - Consequently, the subsequent
<style>element, which would normally be treated as inert data within SVG, is now interpreted as an HTML style tag. - HTML parsing rules dictate that a
<style>tag's content is treated as CSS, but its closing tag is typically</style>. If the attacker crafts the payload such that the</style>tag is missing or misinterpreted, the<img src=x onerror=alert(1)>can then "break free" from the style block and be parsed as an active HTML element, executing the XSS. The browser, confused by the rapid context changes, fails to correctly scope the elements.
Root Cause 2: Unpredictable Changes in Markup Type
This is even more challenging because the context switch is triggered by the sanitizer's actions. The sanitizer removes elements it deems dangerous, but this removal can change the parsing context for the remaining elements, inadvertently creating a vulnerability. An example involves the <noembed> element:
Here's the mutation:
- The original markup establishes a nested context: HTML (
noembed) -> SVG (svg) -> HTML (b). - A sanitizer, designed to remove potentially dangerous or deprecated elements, might remove the
<noembed>tag. - However, if the sanitizer removes
<noembed>but leaves its children intact, the initial parsing context is drastically altered. The browser now starts parsing directly from<svg><b>.... - This shift means the subsequent
<style>element and the embedded<img>tag are processed under a different, now vulnerable, HTML context, leading to XSS. The sanitizer, operating on a static view, cannot predict the dynamic re-parsing that occurs after its modifications.
These examples vividly illustrate that MXSS is not a simple string manipulation problem but a deep challenge rooted in the complex, heuristic-driven parsing mechanisms of web browsers, where context is everything and subtle changes can have profound security implications.
Demo / Proof of Concept
▶ Watch: The strategic solution: changing the HTML standard (23:00)
While Dr.-Ing. Mario Heiderich's talk was heavily focused on the technical underpinnings and strategic solutions for Mutation XSS, time constraints prevented extensive live demonstrations of all attack vectors. Heiderich did, however, briefly showcase a second-generation MXSS example, illustrating how a seemingly innocuous input like <input article xmlns:a="b"> could cause the browser to generate a "massive contraption" of HTML, demonstrating the browser's aggressive auto-correction and markup generation.
Crucially, the talk highlighted a real-world proof of concept for the third-generation noscript bypass. This vector was not merely theoretical but was successfully exploited by researcher Masato Kinugawa on Google's index page, resulting in a significant security bounty. This practical demonstration of MXSS bypassing a major platform's defenses underscored the severity and real-world applicability of the discussed vulnerabilities. Heiderich also referenced the availability of his slides for those wishing to copy-paste and test the older first-generation MXSS vectors in browsers like Internet Explorer. The speaker also mentioned a video by Fabian which explains the Google bypass in detail, along with links to the specific code revision of Google's sanitizer that contained the vulnerability.
Defensive Implications
▶ Watch: The origin story of MXSS research (Q&A) (29:00)
The detailed exploration of MXSS reveals a profound challenge for web defenders: the inherent difficulty for a JavaScript-based sanitizer to guarantee security when it cannot fully predict the browser's final parsing context. As Heiderich emphasized, a sanitizer doesn't know if its output will be placed into an iframe, a srcdoc, or some other dynamic context, each with potentially different parsing rules. This uncertainty renders traditional sanitization, even with meticulous care, unreliable against sophisticated MXSS attacks.
To address this, two levels of defense are being pursued:
- Tactical Fixes (Short-Term):
For existing JavaScript sanitizers like DOMPurify, immediate improvements were necessary. In collaboration with Mihawk Mikowski and others, new logic was integrated into DOMPurify. This logic involves parent node checks, where the sanitizer examines the context of an element's parent node to detect any violations of expected markup type. If a context violation is identified (e.g., an HTML element unexpectedly appearing within an SVG context that should only contain SVG elements), the problematic element is removed. This approach has proven effective so far in mitigating the known third-generation MXSS vectors. However, Heiderich explicitly warned against using tools like jsdom for security-sensitive sanitization, describing it as a "steaming pile of garbage" from a security perspective due to numerous unaddressed bugs.
- Strategic Solution (Long-Term):
The ultimate, and most impactful, defensive strategy is to move sanitization out of JavaScript libraries and into the core of web browsers and the HTML standard itself. Heiderich described an eight-year lobbying effort, starting around 2013-2016, to convince browser vendors and standards bodies of this necessity. The argument was simple: a JavaScript library, no matter how well-maintained, cannot reliably secure against context-aware mutations, especially given the rapid evolution of browser engines and parsing quirks. The browser, however, has full knowledge of the rendering context and can therefore perform sanitization correctly and consistently.
This strategic push has yielded significant results:
- HTML Sanitizer API Specification: A formal specification for browser-native HTML sanitization has been developed.
- Browser Vendor Commitment: Major browser vendors, including Google (Chrome), Mozilla (Firefox), and Microsoft, have committed to implementing this standard. While Apple's commitment (for Safari) was less certain at the time of the talk, the backing of the other major players is transformative.
- Core HTML Standard Change: The specification is so robust that it is expected to fundamentally alter the HTML standard. The goal is for HTML itself to automatically sanitize content upon assignment to the DOM, particularly when using methods like
innerHTML. This will be achieved through new, context-aware methods such assetSafeInnerHTML. - Implementation Progress: Implementations are already present in Chrome and Firefox, initially behind flags, with plans to make them default behavior soon (e.g., within a month of the talk for Firefox).
- Enhanced Security: The key advantage is that any bypasses found in the browser's native sanitizer would be considered critical vulnerabilities and would be fixed rapidly by browser vendors, offering a level of support and reliability impossible for a single JavaScript library.
This shift signifies a major architectural change for web security, moving towards a future where the browser is an active participant in preventing XSS by handling untrusted HTML content in a natively secure, context-aware manner.
Key Takeaways
- MXSS is a persistent and complex XSS variant: Mutation Cross-Site Scripting (MXSS) exploits how web browsers parse and "optimize" HTML, turning seemingly safe, sanitized input into executable code, even after traditional defenses have been applied.
- Traditional sanitization is insufficient: JavaScript-based sanitizers like DOMPurify, while crucial, cannot reliably prevent all MXSS attacks because they operate without full knowledge of the final rendering context in the user's browser, leading to unpredictable parsing outcomes.
- Browser context switching is the root cause: The latest generation of MXSS attacks leverages predictable and unpredictable changes in parsing contexts (e.g., HTML, SVG, XML) to confuse the browser and break free malicious code, as demonstrated by the
noscriptbypass on Google's index page. - Strategic shift to browser-native sanitization: The long-term solution involves moving HTML sanitization into the core of web browsers through a standardized HTML Sanitizer API. This empowers browsers to perform context-aware sanitization automatically.
- HTML standard is evolving: Major browser vendors (Google, Firefox, Microsoft) are committed to implementing the HTML Sanitizer API, which will fundamentally change the HTML specification to include methods like
setSafeInnerHTMLfor automatic, secure DOM assignments. - Defenders must adapt: While browser-native sanitization is on the horizon, developers must continue to use robust, up-to-date JavaScript sanitizers (like DOMPurify with its latest parent node checks) and be aware of MXSS to protect against current threats.
About the Speaker(s)
Dr.-Ing. Mario Heiderich is a distinguished figure in web security, serving as the Head of Cure53, a prominent penetration testing company based in Berlin. Beyond his leadership role, he is an active academic, delivering a block lecture annually at the Ruhr University in Bochum. Heiderich is perhaps best known for his pioneering work on Mutation Cross-Site Scripting (MXSS), a vulnerability class that he not only discovered and named but has also dedicated significant effort to mitigating and advocating for strategic solutions. He is also the primary maintainer of DOMPurify, a widely adopted and highly regarded open-source HTML sanitization library. His extensive experience in both practical penetration testing and academic research, coupled with his commitment to open-source security, positions him as a leading authority on complex web vulnerabilities and their systemic solutions.
Reviews
Dr. Zero (Offensive Security Researcher) — MUST SEE
Heiderich is one of the few people who can stand on stage and explain exactly why his own tool—DOMPurify—is fundamentally losing the war against browser parsing quirks. This is foundational web security research that outlines the necessary death of JavaScript-based sanitization in favor of the browser-native HTML Sanitizer API. If you touch the DOM, this is mandatory viewing.
Heather Calloway (CISO) — STRONG ACCEPT
Heiderich demonstrates that client-side HTML sanitization is essentially a losing game because modern browser parsers will mutate 'safe' strings into active exploits. The strategic value here isn't the payload syntax—it's the timeline for the new W3C HTML Sanitizer API. If you run a large engineering org, this is your signal to start planning the architectural shift away from JavaScript-based sanitization libraries.