Use after free in HTML (CVE-2026-19559)
A helper in Blink that flattens assigned slot nodes iterated the slot's assigned-nodes vector by reference while recursing into nested slot assignment recalculations. A nested recalculation could clear that vector and free its backing memory, so the loop would then read freed memory, a use-after-free that could potentially lead to memory corruption in the renderer.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 15 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: A potential Use-After-Free (UAF) vulnerability exists in HTMLSlotElement's CollectFlattenedAssignedNodes helper due to range-iterating assigned_nodes_ by reference while synchronously recursing into slot assignment recalculations. A nested assignment recalculation can clear the slot's assigned nodes, prompt-freeing the backing storage of the iterated vector and causing subsequent iterations to dereference freed memory. Four sibling loops in the same file were previously protected against this hazard with defensive copies, but this instance was missed.
Affected files:
third_party/blink/renderer/core/html/html_slot_element.cc
Estimated timestamp from git blame: 2018-01-18
Root Cause Analysis
In third_party/blink/renderer/core/html/html_slot_element.cc, the helper function CollectFlattenedAssignedNodes resolves a flattened list of assigned nodes by traversing slot hierarchies.
The function binds a const reference to the slot's assigned_nodes_ HeapVector<Member<Node>> and iterates over it by reference:
// third_party/blink/renderer/core/html/html_slot_element.cc
HeapVector<Member<Node>> CollectFlattenedAssignedNodes(const HTMLSlotElement& slot) {
DCHECK(slot.SupportsAssignment());
const HeapVector<Member<Node>>& assigned_nodes = slot.AssignedNodes(); // Aliases slot.assigned_nodes_
HeapVector<Member<Node>> nodes;
if (assigned_nodes.empty()) {
// ...
} else {
for (auto& node : assigned_nodes) { // <-- Iterating by reference
DCHECK(node->IsSlotable());
if (auto* assigned_node_slot =
ToHTMLSlotElementIfSupportsAssignmentOrNull(*node))
nodes.append_range(CollectFlattenedAssignedNodes(*assigned_node_slot)); // <-- Synchronous recursion
else
nodes.push_back(node);
}
}
return nodes;
}
During recursive resolution of nested slots, the loop body can trigger slot assignment recalculations (RecalcAssignment()) on another shadow root. If a cross-tree assignment occurs during this nested recalculation, it can mark the outer slot's shadow root as dirty (needs_assignment_recalc_ = true).
Upon returning to the outer loop, the subsequent iteration calls AssignedNodes() on the next assigned node. Because its containing shadow root is now marked dirty, it executes a nested RecalcAssignment() on the outer shadow root. This nested recalculation loops over all slots and calls slot->WillRecalcAssignedNodes(), which runs assigned_nodes_.clear(). In Blink's Oilpan garbage-collected allocator (cppgc), clearing the HeapVector shrinks its capacity to 0 and prompt-frees the backing memory. The outer loop then resumes and dereferences the now-freed HeapVectorBacking<Member<Node>>, resulting in a high-severity Use-After-Free (UAF) condition.
Four sibling loops in html_slot_element.cc (AttachLayoutTreeForSlotChildren, DetachLayoutTree, RebuildDistributedChildrenLayoutTrees, and RecalcStyleForSlotChildren) were previously patched with defensive copies for this exact hazard (referencing crbug.com/497830330 and crbug.com/520167277), but CollectFlattenedAssignedNodes was missed.
Suggested Potential Steps to Reproduce
Note: The following are potential steps derived from logical tracing of the code; our tooling does not currently have the capability to execute proof-of-concept code.
-
Setup DOM Tree & Shadow Roots:
- Create a host element
host1and attach an open author shadow rootR1in manual slot assignment mode. - Inside
R1, append a slot elementS1. - Append two children to
host1:S2(which is also a slot element) andS3(a standard element). - Assign both
S2andS3toS1using manual assignment:S1.assign(S2, S3).
- Create a host element
-
Setup Nested Shadow Root:
- Attach an open author shadow root
R2in manual slot assignment mode toS2. - Dirty
R2's slot assignment flag (e.g., by modifying its slots or appending a child toS2).
- Attach an open author shadow root
-
Call Flattening API:
- Invoke the JS API
S1.assignedNodes({flatten: true}), which routes toCollectFlattenedAssignedNodes(S1). - The loop binds a reference to
S1's assigned nodes:[S2, S3].
- Invoke the JS API
-
Trigger UAF Flow:
- Iteration 1: Processes
S2. SinceS2is a slot, the code recurses intoCollectFlattenedAssignedNodes(S2). - Inside the recursion,
S2.AssignedNodes()invokesR2'sRecalcAssignment(). - During
R2's recalculation, reassignS3fromS1(inR1) to a slot inR2via manual assignment (S2.assign(S3)). This triggersHTMLSlotElement::AssignonS2. HTMLSlotElement::Assigndetects thatS3's previous slot wasS1(belonging toR1) and invokesS1->DidSlotChange(), which setsR1.needs_assignment_recalc_ = true.- The recursive call completes and returns control to
S1's outer loop. - Iteration 2: Processes
S3. The loop callsS3.AssignedNodes(). - Since
S3resides inR1's scope andR1is dirty, this triggers a nestedR1.RecalcAssignment(). R1.RecalcAssignment()callsS1->WillRecalcAssignedNodes(), which runsassigned_nodes_.clear()and prompt-freesS1's backing storage.- The loop continues to the next iteration step, attempting to read or increment the iterator pointing to the now-freed backing store of
S1->assigned_nodes_.
- Iteration 1: Processes
Suggested Fix
The fix is identical to the remediations applied to the other four sibling loops in the same file. CollectFlattenedAssignedNodes must create a defensive copy of the slot's assigned nodes vector instead of holding and iterating a live const reference:
diff --git a/third_party/blink/renderer/core/html/html_slot_element.cc b/third_party/blink/renderer/core/html/html_slot_element.cc
--- a/third_party/blink/renderer/core/html/html_slot_element.cc
+++ b/third_party/blink/renderer/core/html/html_slot_element.cc
@@ -94,7 +94,8 @@ HeapVector<Member<Node>> CollectFlattenedAssignedNodes(
const HTMLSlotElement& slot) {
DCHECK(slot.SupportsAssignment());
- const HeapVector<Member<Node>>& assigned_nodes = slot.AssignedNodes();
+ // Defensive copy to prevent UAF from synchronous slot assignment recalculation.
+ const HeapVector<Member<Node>> assigned_nodes = slot.AssignedNodes();
HeapVector<Member<Node>> nodes;
if (assigned_nodes.empty()) {
// Fallback contents.
Evaluated with Chrome root at commit: 94d9235ebe3b7276e5284f0dc5d55577ff949908
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 function held a live reference to the slot's assigned-nodes vector and iterated it while a synchronous nested slot assignment recalculation could clear that same vector and free its backing storage.
Impact
The text rates this as a high-severity use-after-free in the renderer that could potentially be exploited for memory corruption, though no proof-of-concept was executed and the report is a code-tracing deduction.
What the attacker needed
Ability to run JavaScript in a page; use of shadow DOM slots in manual mode
The fix
The helper should take a defensive copy of the assigned-nodes vector instead of iterating a live reference, matching the four sibling loops already patched for the same hazard.
How it was found
- Create a host with an open shadow root in manual slot assignment mode containing a slot, and give the host a nested slot child plus a normal element, assigning both to the outer slot.
- Attach a second manual-mode shadow root to the nested slot and mark its assignment as dirty.
- Call the flattening API on the outer slot, which starts iterating its assigned nodes.
- During recursion into the nested slot, reassign the normal element to the inner slot, which marks the outer shadow root dirty.
- On the next loop iteration the dirty outer root recalculates, clears the outer slot's assigned nodes and frees the backing store.
- The loop then continues over the freed memory.
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.
A slot is a placeholder in a web component that decides where child content appears. The browser keeps a list of the children currently placed in each slot, and this code walked that list while other code could empty and discard it mid-walk. Reading a list after it has been thrown away is a use-after-free, which can crash the browser tab or, in the worst case, let an attacker 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.