Inappropriate implementation in XML (CVE-2026-14000)
A logic error in Blink's XML fragment parser fails to clear the namespace reset state when closing an HTML template element, causing subsequent sibling elements to inherit a null namespace. This could allow a mutation XSS primitive that bypasses DOM-based sanitizers.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 43 days
Flapjack, 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: A logic error in Blink's XML fragment parser fails to clear the namespace reset state when closing an HTML <template> element. This causes subsequent sibling elements to incorrectly inherit a null namespace instead of the default namespace. This potential vulnerability provides a mutation XSS (mXSS) primitive that can bypass DOM-based sanitizers.
Affected files:
third_party/blink/renderer/core/xml/parser/xml_document_parser.ccthird_party/blink/renderer/core/xml/parser/xml_document_parser_rs.cc
Estimated timestamp from git blame: Unknown (Google3 checkout)
Description
There is a potential logic error in XMLDocumentParser (and its Rust counterpart XMLDocumentParserRs) regarding how it tracks namespace resets during XML fragment parsing.
When parsing an XML fragment, the parser uses ancestor_resetting_namespace_ to track the outermost element that reset the default namespace to null (e.g., via xmlns="").
In XMLDocumentParser::StartElementNs, if the parser encounters an HTMLTemplateElement, it pushes the template's content (a DocumentFragment) onto its internal node stack instead of the template element itself:
if (auto* template_element = DynamicTo<HTMLTemplateElement>(*new_element))
PushCurrentNode(template_element->content());
However, ancestor_resetting_namespace_ is correctly set to the HTMLTemplateElement if it performed a namespace reset.
In XMLDocumentParser::EndElementNs, the parser attempts to clear this tracking variable when the resetting element is closed. It does this by checking if the currently closing node n matches ancestor_resetting_namespace_:
ContainerNode* n = current_node_;
auto* element = DynamicTo<Element>(n);
if (!element) {
PopCurrentNode();
return;
}
if (ancestor_resetting_namespace_ == n) {
ancestor_resetting_namespace_ = nullptr;
}
When the </template> tag is reached, n is the DocumentFragment. Because a DocumentFragment is not an Element, the DynamicTo<Element>(n) cast fails. The function calls PopCurrentNode() and returns early. This completely bypasses the cleanup logic. Consequently, ancestor_resetting_namespace_ remains set, and all subsequent sibling elements of the <template> incorrectly inherit a null namespace.
Potential Exploitation Steps
(Note: These are suggested steps based on static analysis, as our tooling cannot currently run a live proof-of-concept).
An attacker could exploit this bug against an application that parses untrusted input as XML, sanitizes the DOM, and serializes it into an HTML context:
- The attacker provides a crafted XML fragment:
<html:template xmlns:html="http://www.w3.org/1999/xhtml" xmlns=""></html:template><script>alert(1)</script>. - The
html:prefix ensures the template is created as anHTMLTemplateElement(pushing aDocumentFragmentto the stack), whilexmlns=""explicitly triggers the namespace reset. - The parser fails to clear
ancestor_resetting_namespace_when the template closes. - The parser encounters the
<script>tag. Because the namespace reset state leaked, the<script>tag is instantiated in the null namespace as a genericElement, rather than anHTMLScriptElement. - A DOM-based sanitizer inspects the tree. Seeing a generic
<script>element in the null namespace, it may assume it is an inert XML tag and allow it. - The application serializes the DOM (e.g., using
XMLSerializer). The serializer notices the null namespace and synthesizes a namespace declaration:<script xmlns="">alert(1)</script>. - The serialized string is injected into an HTML document. The HTML parser ignores the
xmlnsattribute, parses it as a live HTML script, and executes the payload, achieving Cross-Site Scripting (XSS).
Suggested Fix
Modify the cleanup logic in XMLDocumentParser::EndElementNs (and xml_document_parser_rs.cc) to account for <template> elements pushing a DocumentFragment.
One potential approach is to check if ancestor_resetting_namespace_ is a template element, and if the node being popped is that template's content:
ContainerNode* n = current_node_;
// Add cleanup logic before the early return
if (ancestor_resetting_namespace_ == n ||
(ancestor_resetting_namespace_ &&
ancestor_resetting_namespace_->IsTemplateElement() &&
n == static_cast<HTMLTemplateElement*>(ancestor_resetting_namespace_.Get())->content())) {
ancestor_resetting_namespace_ = nullptr;
}
auto* element = DynamicTo<Element>(n);
if (!element) {
PopCurrentNode();
return;
}
Alternatively, ensure ancestor_resetting_namespace_ is properly cleared whenever PopCurrentNode() corresponds to exiting the scope of the resetting element.
Evaluated with Chrome root at commit: b7d0c4d810da1b31400f198c70d9720fc8f0e5a0
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
Likely the parser's cleanup logic for the namespace reset state is bypassed because the template element pushes a DocumentFragment onto the node stack, and the early return for non-Element nodes skips clearing the state.
Impact
This could allow an attacker to achieve Cross-Site Scripting (XSS) by bypassing DOM-based sanitizers, but the text notes that the exploitation steps are suggested based on static analysis and no live proof-of-concept was run.
What the attacker needed
Application parses untrusted XML; application sanitizes DOM; application serializes to HTML
The fix
The cleanup logic in `XMLDocumentParser::EndElementNs` should be modified to account for template elements pushing a DocumentFragment, for example by checking if the node being popped is the template's content and clearing the namespace reset state accordingly.
How it was found
- The attacker provides a crafted XML fragment with a template element that resets the namespace and a script tag.
- The parser fails to clear the namespace reset state when the template closes.
- The parser encounters the script tag and instantiates it in the null namespace as a generic element.
- A DOM-based sanitizer inspects the tree and may allow the generic script element.
- The application serializes the DOM, and the serializer synthesizes a namespace declaration.
- The serialized string is injected into an HTML document, and the script executes.
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 browser reads XML, it tracks which namespace (a way to group element names) each element belongs to. A bug in this tracking means that after a template element closes, the browser forgets to reset the namespace, so later elements are treated as if they have no namespace. This can trick security filters into thinking a script tag is harmless, allowing an attacker to run code in a victim's browser.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.