Use after free in Script (CVE-2026-79195)
A re-entrancy flaw in Blink's XML parser allows synchronous script execution to trigger nested calls to libxml2's xmlParseChunk on the same context, causing a use-after-free and out-of-bounds write. An attacker could potentially achieve remote code execution in the renderer.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 4 months
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 without the Chrome Security team.
Overview: A re-entrancy vulnerability exists in Blink's XML parser where synchronous script execution can lead to nested calls to libxml2's xmlParseChunk on the same context. This allows an inner parse frame to reallocate internal buffers while an outer frame holds raw pointers to them. When the outer frame resumes, it accesses freed memory, potentially leading to an out-of-bounds write and remote code execution in the renderer.
Affected files:
third_party/blink/renderer/core/script/xml_parser_script_runner.ccthird_party/blink/renderer/core/xml/parser/xml_document_parser.ccthird_party/libxml/src/parser.cthird_party/blink/renderer/core/loader/document_loader.ccthird_party/blink/renderer/platform/loader/fetch/url_loader/navigation_body_loader.ccthird_party/blink/renderer/core/frame/local_frame.ccthird_party/blink/renderer/core/page/chrome_client.cc
Estimated timestamp from git blame: 2023-11-02
Summary
There is a potential Use-After-Free (UAF) and Out-Of-Bounds (OOB) write vulnerability in Blink's integration with libxml2. The issue stems from the fact that XMLParserScriptRunner can execute scripts synchronously in a way that bypasses network-level re-entrancy guards. This allows an attacker to force a re-entrant call to xmlParseChunk on the same xmlParserCtxt. The inner parse can reallocate the parser's namespace stack (pushTab), invalidating raw pointers held by the suspended outer parse frame.
Note: The following analysis is based on code inspection and traces. These are suggested/potential steps to trigger the issue, as our tooling does not yet have the ability to run a live proof-of-concept.
Technical Details
- Bypassing Re-entrancy Guards: When an external XML script finishes loading,
XMLParserScriptRunner::PendingScriptFinishedsynchronously callsXMLDocumentParser::ResumeParsing(). Because this originates from a script loading callback rather than aNavigationBodyLoadernetwork read, standard re-entrancy guards likeis_in_on_readable_andin_commit_data_arefalse. - Nested Message Loop: If the resumed parsing executes an inline script that calls
alert(1), it triggersChromeClient::OpenJavaScriptDialog, which creates aScopedPagePauser. This spins a nested message loop. - Synchronous Loader Resumption: When the user dismisses the dialog, the
ScopedPagePauserdestructor callsPage::SetPaused(false). This synchronously propagates down toNavigationBodyLoader::SetDefersLoading(kNone), which immediately callsOnReadable()to read pending Mojo data. - Re-entrant Parse: Because the re-entrancy guards were
false(as established in step 1),OnReadablesuccessfully reads the next chunk of XML data and passes it toXMLDocumentParser::Append, leading to an inner, re-entrant call toxmlParseChunkon the identicalxmlParserCtxtobject. - Use-After-Free in libxml2: The suspended outer parse frame is stopped inside
xmlParseEndTag2(third_party/libxml/src/parser.c), holding a rawconst xmlStartTag *tagpointer to thectxt->pushTabbuffer. If the inner parse processes deeply nested namespace tags,nameNsPushcallsxmlRealloconctxt->pushTab, freeing the memory the outer frame is pointing to. - OOB Write: When the inner parse returns, the outer
xmlParseEndTag2resumes. It accessestag->nsNrfrom the freed memory and passes it toxmlParserNsPop. If an attacker controls this memory and supplies a large positive integer fornsNr, it causes an integer underflow inxmlParserNsPop's loop bounds. This leads to negative-index OOB reads and a subsequent OOB heap write (bucket->index = extra->oldIndex), providing a strong primitive for Remote Code Execution.
Potential Steps to Reproduce
An attacker could potentially trigger this by serving an application/xhtml+xml document using chunked transfer encoding:
- Send Chunk A:
<script src="ext.js"></script>. This pauses the XML parser to wait for the external script. - Send Chunk B:
<a xmlns:p="u"><script>alert(1)</script>. This chunk is safely buffered inpending_src_because the parser is paused. - Send Chunk C: A payload of deeply nested
<foo xmlns:a="1">tags followed by an inline<script>groom()</script>. This sits unread in the Mojo data pipe. - Finish
ext.js: The browser finishes loading the external script. The callback resumes parsing and processes Chunk B. - Trigger Pauser: The
alert(1)in Chunk B executes, creating theScopedPagePauser. - Dismiss Dialog: When the dialog is dismissed,
NavigationBodyLoadersynchronously reads Chunk C, triggering the re-entrant inner parse. - Reallocation and Grooming: The deeply nested tags in Chunk C force
ctxt->pushTabto reallocate, freeing the old buffer. Thegroom()script allocates memory to reclaim the freed buffer and writes a controllednsNrpayload. - Exploitation: The inner parse completes, the outer parse resumes, dereferences the dangling pointer to read the attacker's
nsNr, and executes the OOB write.
Suggested Fix
To prevent this vulnerability, XMLParserScriptRunner::PendingScriptFinished should avoid resuming the parser synchronously on the current call stack. It should instead use PostTask to schedule the resumption, ensuring the C++ stack is unwound and preventing cooperative re-entrancy. This approach is already successfully used by the HTML parser (HTMLParserScriptRunner::PendingScriptFinished).
Alternatively, XMLDocumentParser could maintain a strict internal re-entrancy boolean guard that CHECKs or safely drops nested calls to Append() or ResumeParsing() while a parse chunk is actively executing.
Evaluated with Chrome root at commit: 096fc8fdbfacf2546485756d03f160a3d04fcc9b
Results so far have been promising, but there can be wrong deductions. If this proves to be a false positive, please close as WAI; 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 XML parser script runner resumes parsing synchronously from a script loading callback, bypassing re-entrancy guards, which allows nested parsing on the same context and invalidates raw pointers.
Impact
An attacker could potentially achieve remote code execution in the renderer through an out-of-bounds write.
What the attacker needed
Victim loads a malicious XML document; browser uses vulnerable Blink/libxml2
The fix
The fix should avoid synchronous resumption by using PostTask to schedule parser resumption, or add a re-entrancy guard in XMLDocumentParser.
How it was found
- Send Chunk A: an external script tag, pausing the XML parser.
- Send Chunk B: an inline script that calls alert(1), buffered while paused.
- Send Chunk C: deeply nested namespace tags and a grooming script, unread in the data pipe.
- Finish loading the external script, resuming parsing and processing Chunk B.
- The alert(1) executes, creating a ScopedPagePauser.
- Dismiss the dialog, causing NavigationBodyLoader to synchronously read Chunk C and trigger re-entrant parsing.
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 is loaded, the browser's XML parser can be interrupted by scripts. This report shows that a script can cause the parser to be re-entered while it is still working, leading to memory corruption. An attacker who controls a malicious XML document could exploit this to run code on the victim's computer.
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.