Use after free in Blink (CVE-2026-5872)
A potential reentrancy vulnerability in Blink's multi-node insertion methods allows an attacker's iframe unload handler to reparent a node during argument preparation, bypassing structural safety checks and corrupting the DOM tree. This corruption could lead to use-after-free or type confusion, potentially enabling remote code execution in the renderer process.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 14 days
Project Fortify, an experimental security project, has identified the following potential security issue.
Overview: A potential reentrancy vulnerability exists in Blink's multi-node insertion paths (e.g., append(), prepend()). Synchronous iframe unload events triggered during argument preparation can allow attacker script to reparent a node, bypassing structural safety checks. This blindly splices the node into a new tree while leaving stale pointers in the old parent, corrupting the DOM and enabling potential Use-After-Free (UAF) or type confusion.
Affected files:
third_party/blink/renderer/core/dom/node.ccthird_party/blink/renderer/core/dom/container_node.cc
Estimated timestamp from git blame: 2024-10-29
Summary
There is a potential DOM tree linked-list corruption vulnerability in Blink's variadic DOM mutation methods (append, prepend, before, after, replaceWith, replaceChildren). When multiple nodes are passed to these methods, they are processed by Node::ConvertNodeUnionsIntoNodes, which iteratively removes each node from its current parent. If an argument contains an <iframe>, its removal fires a synchronous unload event.
Malicious JavaScript in the unload handler can reparent a node that was removed in an earlier iteration of the loop. Because the multi-child insertion paths (e.g., ContainerNode::AppendChildren) explicitly skip the RecheckNodeInsertionStructuralPrereq check when the number of new children is greater than 1, the reparented node is blindly inserted into the target container. This corrupts the DOM tree by leaving dangling child pointers in the old parent.
Note: The following are suggested/potential steps, as our setup does not have the ability to execute code to create a working proof of concept.
Potential Steps to Reproduce
- An attacker creates an HTML page and executes JavaScript to create an empty
targetelement, an emptynode1, and anode2containing a same-origin<iframe>. - The attacker registers an
unloadevent listener on the iframe'swindow. - The attacker calls
target.append(node1, node2). - In
Node::ConvertNodeUnionsIntoNodes, Blink iterates over the arguments:node1is detached (node1->remove()).node2is detached (node2->remove()).
- Detaching
node2tears down the iframe, which synchronously fires theunloadevent, pausing C++ execution and running the attacker's JavaScript. - The attacker's
unloadscript executesevilParent.appendChild(node1), reparentingnode1into a new, unrelated DOM element. - C++ execution resumes.
ConvertNodeUnionsIntoNodesreturns[node1, node2]. Critically,node1is no longer an orphan; itsparentNode()isevilParent. - Execution proceeds to
ContainerNode::AppendChildren. AppendChildrenhas a check:if (new_children.size() == 1u) { ... RecheckNodeInsertionStructuralPrereq(...) }. Because there are 2 children, this block is skipped.node1is passed toContainerNode::AppendChildCommon, which updatesnode1'sparentNode,nextSibling, andpreviousSiblingpointers to link it intotarget.- However,
node1was never properly removed fromevilParent.evilParentstill holds raw pointers tonode1in its internal child linked list. - The DOM tree is now corrupted with overlapping sibling and parent pointers, which will likely confuse Blink's Layout and Style engines and lead to a Use-After-Free.
Technical Details
- File:
third_party/blink/renderer/core/dom/node.ccNode::ConvertNodeUnionsIntoNodessequentially callsnode->remove(exception_state)(line ~1151). This triggersContainerNode::RemoveChild, which fires synchronous detachment events. - File:
third_party/blink/renderer/core/dom/container_node.ccContainerNode::AppendChildren(and similar methods likeInsertBefore) only perform the post-removal sanity checkRecheckNodeInsertionStructuralPrereqifnew_children.size() == 1u(line ~1156). When multiple children are inserted, this crucial guard is bypassed. - Inside
ContainerNode::InsertNodeVector, the debug assertionDCHECK(!target_node->parentNode())catches this in debug builds, but it compiles to a no-op in release builds, allowing the DOM corruption to proceed.
Impact
DOM tree corruption is a highly reliable primitive for memory corruption. Blink's layout objects, layers, and style recalculation engines rely heavily on the integrity of the DOM tree. Crossing sibling pointers between unrelated subtrees can deterministically trigger Use-After-Free or Type Confusion vulnerabilities, leading to Remote Code Execution (RCE) in the sandboxed renderer process.
Suggested Fix
Ensure that the structural integrity check is performed regardless of the number of nodes being inserted.
- Modify
ContainerNode::AppendChildren,InsertBefore,ReplaceChild, andReplaceChildrento unconditionally callRecheckNodeInsertionStructuralPrereq(or a variant of it designed for multi-node vectors) after theConvertNodeUnionsIntoNodesstep has completed and beforeInsertNodeVectoris called. - Alternatively, modify
Node::ConvertNodeUnionsIntoNodesto verify that all nodes in the returnedVectorOf<Node>are orphans (!node->parentNode()) immediately before returning, and throw an exception if any node has acquired a parent during the removal loop.
Evaluated with Chrome root at commit: a3f5fcb392f2902650ca2b71820e7e418787e18b
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. Please feel free to reach out to me if you have concerns or feedback.
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 multi-child insertion path skips the structural prerequisite check when more than one child is inserted, allowing a node reparented during a synchronous unload event to be inserted while still referenced by its old parent.
Impact
DOM tree corruption could deterministically trigger use-after-free or type confusion, potentially leading to remote code execution in the sandboxed renderer process.
What the attacker needed
Victim visits attacker-controlled page; same-origin iframe; JavaScript enabled
The fix
The structural integrity check should be performed unconditionally after argument conversion and before insertion, or the conversion step should verify all nodes are orphans and throw an exception if not.
How it was found
- Create an empty target element, an empty node1, and a node2 containing a same-origin iframe.
- Register an unload event listener on the iframe's window.
- Call target.append(node1, node2).
- During argument processing, node1 and node2 are detached; detaching node2 fires the unload event synchronously.
- In the unload handler, reparent node1 into a new element (evilParent).
- Execution resumes and node1 is inserted into target without the structural check, leaving evilParent with stale pointers to node1.
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 you add several elements to a web page at once, the browser first removes each from its old parent. If one of those elements is an iframe, removing it triggers an 'unload' event, and JavaScript in that event can move an already-removed element to a new parent. The browser then inserts that element again without checking it is still detached, leaving the old parent with a broken pointer to it. This can crash the browser or, in theory, let an attacker run 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.