Inappropriate implementation in HTMLParser (CVE-2026-13977)
Blink's HTML fragment parser does not copy attributes of the context element into its internal stack representation, so MathML annotation-xml elements with an encoding attribute are not recognised as HTML integration points. This parser divergence could let markup that a sanitiser deems safe become executable when inserted, enabling mutation XSS.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 46 days
Project Fortify, an experimental security project, has identified the following potential security issue. If you're a feature owner CC-ed on this bug, please do your best to review these reports. Please see https://chromium.googlesource.com/chromium/src/+/main/docs/security/ai-generated-security-bugs-faq.md for more information.
Overview: Blink's HTML fragment parser fails to preserve attributes of the context element in its internal stack representation. This causes MathML <annotation-xml> elements with specific encodings to be incorrectly treated as non-integration points, leading to a parser divergence that enables mutation XSS (mXSS).
Affected files:
third_party/blink/renderer/core/html/parser/html_stack_item.hthird_party/blink/renderer/core/html/parser/html_tree_builder.ccthird_party/blink/renderer/core/html/parser/html_element_stack.cc
Estimated timestamp from git blame: Unknown (Google3 checkout)
Summary
A potential vulnerability in Blink's HTML fragment parser may allow for mutation XSS (mXSS). The parser fails to copy attributes from the context element when initializing the parsing stack for fragment parsing (e.g., via innerHTML or setHTMLUnsafe). This can lead to a divergence in how HTML integration points are identified, allowing malicious markup to bypass sanitization.
Root Cause Analysis
When performing fragment parsing, the context element is represented in the parser's stack by an HTMLStackItem. The constructor used for this purpose (kItemForContextElement) in third_party/blink/renderer/core/html/parser/html_stack_item.h neglects to copy the attributes of the element:
// third_party/blink/renderer/core/html/parser/html_stack_item.h
HTMLStackItem(ContainerNode* node, ItemType type)
: node_(node), token_name_(html_names::HTMLTag::kUnknown) {
switch (type) {
case kItemForContextElement:
token_name_ = HTMLTokenName::FromLocalName(GetElement()->localName());
namespace_uri_ = GetElement()->namespaceURI();
is_document_fragment_node_ = false;
// Attributes are not copied here, and num_token_attributes_ remains 0.
break;
// ...
}
}
Because attributes are missing, the check in HTMLElementStack::IsHTMLIntegrationPoint fails for MathML <annotation-xml> elements. This check depends on the encoding attribute to determine if the element should be treated as an HTML integration point:
// third_party/blink/renderer/core/html/parser/html_element_stack.cc
bool HTMLElementStack::IsHTMLIntegrationPoint(HTMLStackItem* item) {
if (item->HasTagName(mathml_names::kAnnotationXmlTag)) {
Attribute* encoding_attr = item->GetAttributeItem(mathml_names::kEncodingAttr);
if (encoding_attr) {
// ... check for text/html or application/xhtml+xml
}
return false; // Always taken if attributes were not preserved
}
// ...
}
Security Impact
When IsHTMLIntegrationPoint incorrectly returns false, the parser may remain in "Foreign Content" mode. In this mode, HTML-specific tokenizer state transitions are bypassed. For example, a <style> tag inserted into this context will not trigger the RAWTEXT tokenizer state. Subsequent content, such as <img src=x onerror=...> , will then be parsed as live HTML elements with active event handlers rather than inert text inside the style block.
This creates an mXSS primitive where a sanitizer might correctly identify an integration point and deem the markup safe, but Blink's fragment parser divergence causes it to materialize executable code upon insertion.
Potential Reproduction Steps
Note: These steps are based on code analysis and have not been verified with a live proof-of-concept.
- Create a MathML
<annotation-xml>element and set itsencodingattribute to"text/html". - Append this element to the document.
- Assign the following string to its
innerHTML:'<style><img src=x onerror=alert(document.domain)></style>'. - If the vulnerability exists, the
onerrorhandler will fire because the<img>tag is parsed as a live element instead of text within the<style>block.
const ax = document.createElementNS('http://www.w3.org/1998/Math/MathML','annotation-xml');
ax.setAttribute('encoding','text/html');
document.body.append(ax);
ax.innerHTML = '<style><img src=x onerror=alert(document.domain)></style>';
Suggested Fix
Modify the HTMLStackItem initialization for the fragment context element to correctly preserve attributes. This involves calculating the number of attributes on the context element and using Blink's AdditionalBytes allocation mechanism to store them inline in the HTMLStackItem, similar to how the Create method handles tokens.
Evaluated with Chrome root at commit: 1a8d40fc44df2088d5945c0bf53584038aa1614a
Results so far have been promising, but there can be wrong deductions. Feel free to adjust as follows:
- If you are familiar with the severity guidelines, you may adjust the severity.
- If this is a false positive, and there's no work to be done, please close as WAI.
- If there is work to do here but not a vulnerability, please change the issue type to Task/Bug/FR.
Data from false positives will be used to improve accuracy over time. And please feel free to reach out to me directly if you have concerns or feedback on the project.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The HTMLStackItem constructor for the fragment context element does not copy the element's attributes, so checks that rely on those attributes (such as the encoding attribute on MathML annotation-xml) fail.
Impact
A sanitiser might correctly identify an integration point and deem the markup safe, but Blink's fragment parser divergence could cause it to materialise executable code upon insertion; the reproduction steps are based on code analysis and have not been verified with a live proof-of-concept.
What the attacker needed
Attacker-controlled HTML inserted via innerHTML or…; a sanitiser that trusts integration-point handling; victim loads the crafted page
The fix
The HTMLStackItem initialization for the fragment context element should be modified to correctly preserve attributes, using Blink's AdditionalBytes allocation mechanism to store them inline.
How it was found
- Create a MathML annotation-xml element and set its encoding attribute to text/html.
- Append this element to the document.
- Assign a string containing a style block with an img tag carrying an onerror handler to the element's innerHTML.
- If the vulnerability exists, the onerror handler fires because the img tag is parsed as a live element instead of text inside the style block.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a web page inserts HTML into an element, the browser parses that HTML in a special mode. The parser keeps a simplified copy of the surrounding element, but here it forgets to copy that element's attributes. Because of that, the browser misjudges how to treat certain MathML elements, and content that should be inert text can become live HTML, including event handlers that run code.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.