Skip to content
Memory corruption Advisory Advanced CVE-2026-87636

Type confusion in XML (CVE-2026-87636)

A logic error in libxslt's document() function can return the live stylesheet document when URI resolution fails, allowing an attacker to overwrite internal psvi fields with integer IDs via generate-id(). This type confusion could lead to arbitrary code execution during transformation.

Google Chrome

Originally disclosed on Chrome VRP

  • Fix shipped in 6 months

Flapjack (go/flapjack), an LLM-powered static analysis tool, has identified the following potential security issue.

Overview: A logic error in xsltDocumentFunction allows an attacker to obtain a reference to the active stylesheet document. By applying generate-id() to uncompiled instruction nodes in this document, internal psvi fields are overwritten with integer IDs, leading to a potential type confusion and arbitrary code execution during transformation.

Affected files:

  • third_party/libxslt/src/libxslt/functions.c

Estimated timestamp from git blame: 2015-06-23

Summary

A potential type confusion vulnerability exists in libxslt's document() function. When URI resolution fails, the function can incorrectly return the active stylesheet document itself instead of an empty node-set. This exposure allows an attacker to manipulate the document's internal metadata using the generate-id() function, leading to type confusion when the stylesheet is later processed.

Technical Details

In third_party/libxslt/src/libxslt/functions.c, the xsltDocumentFunction handles the XSLT document() call. The function attempts to resolve the URI for the document using xmlBuildURI:

C
336:         URI = xmlBuildURI(url, base);
337:         if (base != NULL)
338:             xmlFree(base);
339:         if (URI == NULL) {
340:             if ((tctxt != NULL) && (tctxt->style != NULL) &&
341:                 (tctxt->style->doc != NULL) &&
342:                 (xmlStrEqual(URI, tctxt->style->doc->URL))) {
343:                 /* This selects the stylesheet's doc itself. */
344:                 valuePush(ctxt, xmlXPathNewNodeSet((xmlNodePtr) tctxt->style->doc));
345:             } else {
346:                 valuePush(ctxt, xmlXPathNewNodeSet(NULL));
347:             }
348:         } else {
349:             xsltDocumentFunctionLoadDocument(ctxt, URI, fragment);
350:             xmlFree(URI);
351:         }

If xmlBuildURI returns NULL (which happens if base is an invalid URI like invalid://::), the code checks if URI is equal to the stylesheet document's URL. If the stylesheet was loaded from memory (e.g., via XSLTProcessor.importStylesheet()), tctxt->style->doc->URL is NULL. Since xmlStrEqual(NULL, NULL) returns 1, the function pushes the live stylesheet document onto the XPath stack.

This short-circuit logic bypasses a previous fix (issue 413080347) in xsltDocumentFunctionLoadDocument, which securely copies the document and strips internal psvi pointers.

Once the live stylesheet document is returned, an attacker can use XPath to select an uncompiled XSLT instruction node (like <xsl:message>) whose psvi field is still NULL. Calling the generate-id() function on this node in xsltGenerateIdFunction assigns it a new ID by incrementing tctxt->currentId and storing this integer directly into the psvi field:

C
796:         id = ++tctxt->currentId;
797:         *psviPtr = (void *) (size_t) id;

When the XSLT engine subsequently evaluates this instruction in xsltApplySequenceConstructor (transform.c:2736), it expects the psvi field to be a valid pointer to an xsltStylePreComp structure:

C
2736:             xsltStylePreCompPtr info = (xsltStylePreCompPtr) cur->psvi;
...
2756:             if (info->func != NULL) {
...
2761:                 info->func(ctxt, contextNode, cur, (xsltElemPreCompPtr) info);

Because info is now an attacker-controlled integer (the generated ID), dereferencing it to call info->func results in a type confusion. An attacker could potentially spray the heap and increment currentId (by calling generate-id() repeatedly) to point to a controlled fake xsltStylePreComp object, leading to Remote Code Execution in the renderer process.

Suggested Steps to Reproduce (Theoretical)

  1. Load a malicious XSLT stylesheet from a memory buffer (e.g., using XSLTProcessor.importStylesheet()).
  2. In the XML input, include a node with an invalid base URI: <foo xml:base="invalid://::"/>.
  3. In the stylesheet, call document('', $foo_node). This forces xmlBuildURI to return NULL and exposes the active stylesheet document.
  4. Select an uncompiled instruction node (e.g., <xsl:message>) from the returned document using XPath.
  5. Call generate-id() on dummy nodes to increment currentId to a predictable heap address where a fake xsltStylePreComp object is sprayed.
  6. Call generate-id() on the uncompiled instruction node to overwrite its psvi field with this target address.
  7. Trigger the execution of the corrupted instruction node in the stylesheet.
  8. The engine dereferences the fake object and calls the attacker-controlled function pointer.

Note: These are suggested steps, as this AI agent does not yet have the ability to run code to verify the exploit end-to-end.

Suggested Fix

In xsltDocumentFunction, remove the short-circuit logic that directly pushes tctxt->style->doc. Instead, always rely on xsltDocumentFunctionLoadDocument, which handles the safe copying of the stylesheet document and stripping of psvi fields. Alternatively, explicitly check that URI and tctxt->style->doc->URL are not NULL before calling xmlStrEqual.

Evaluated with Chrome root at commit: 9760e6c70cd33a320713361f17c6dcca85648c0f


Results from Flapjack so far have been promising, but it can be wrong in its deductions. At this time, it does not produce proof of concepts or fuzzer tests. If this proves to be a false positive, please close as WAI; data from false positives will be used to improve Flapjack’s accuracy over time. And please feel free to reach out to me directly if you have concerns or feedback on the project.

The original report as published on the Chromium issue tracker. Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

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 code checks if the resolved URI equals the stylesheet's URL without ensuring neither is NULL, so when both are NULL the comparison succeeds and the live stylesheet document is returned instead of an empty node-set.

Impact

An attacker could potentially spray the heap and increment currentId to point to a controlled fake object, leading to Remote Code Execution in the renderer process.

What the attacker needed

Ability to supply a malicious XSLT stylesheet; stylesheet loaded from memory (URL is NULL); XML input with invalid base URI

The fix

The short-circuit logic that directly pushes the stylesheet document should be removed, always relying on the safe loading function, or explicitly check that both URIs are not NULL before comparing.

How it was found

  1. Load a malicious XSLT stylesheet from a memory buffer.
  2. Include an XML node with an invalid base URI.
  3. Call document() with an empty string and the node to force URI resolution to fail.
  4. Select an uncompiled instruction node from the returned stylesheet document.
  5. Call generate-id() on dummy nodes to increment currentId to a predictable heap address.
  6. Call generate-id() on the uncompiled instruction node to overwrite its psvi field.

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.

This report describes a bug in a library that processes XML stylesheets. When a stylesheet asks for another document but gives a bad address, the library accidentally hands back the stylesheet itself. The attacker can then use a function that generates IDs to corrupt internal pointers, which might let them run their own code.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More from Google Chrome

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.