Use after free in Forms (CVE-2026-13848)
A static-analysis report claims that HTMLOptionElement::RemovedFrom does not check whether a state-preserving atomic move is in progress, so a synchronous DOM mutation can occur during moveBefore. This could leave a detached subtree with live frames and layout objects, potentially leading to a use-after-free or a security invariant crash.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 34 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: HTMLOptionElement::RemovedFrom lacks a StatePreservingAtomicMoveInProgress check, allowing synchronous DOM mutations during moveBefore. This can lead to detached subtrees with live frames and layout/DOM tree desynchronization, potentially enabling a use-after-free.
Affected files:
third_party/blink/renderer/core/html/forms/html_option_element.ccthird_party/blink/renderer/core/html/forms/html_select_element.ccthird_party/blink/renderer/core/html/forms/html_selected_content_element.cc
Estimated timestamp from git blame: 2024-10-10
Potential Use-After-Free via HTMLOptionElement::RemovedFrom and moveBefore DOM Mutation
Overview
A potential security vulnerability exists in Blink's handling of the state-preserving atomic move API (moveBefore). Specifically, HTMLOptionElement::RemovedFrom does not perform a StatePreservingAtomicMoveInProgress() check before calling into HTMLSelectElement::OptionRemoved. In default production configurations (where the experimental <selectedcontent> specification is disabled), this allows OptionRemoved to synchronously trigger a DOM mutation via ReplaceChildren on a connected <selectedcontent> element during the removal phase of moveBefore. This synchronous mutation can bypass the atomic move invariants, leading to a detached DOM subtree with live frames and layout/DOM tree desynchronization, which can result in a Use-After-Free (UAF) or an invariant security check crash.
Note: Since our tooling agent currently lacks the capability to run code dynamically, these findings and steps are based on static analysis of the source code and represent potential behavior.
Root Cause Analysis
During a state-preserving atomic move (such as when invoking moveBefore() on a node containing a <selectedcontent> element and an iframe), the document-wide flag StatePreservingAtomicMoveInProgress is set to true to ensure that frame disconnects and layout tree detachment are safely skipped during the removal phase (see container_node.cc).
However, during this phase:
HTMLOptionElement::RemovedFrom()is invoked on a removed option element (seehtml_option_element.cc:636). It fails to verify ifStatePreservingAtomicMoveInProgress()is active.- It calls
old_ancestor_select->OptionRemoved(*this, old_ancestor_select_child)(line 654). - Under the default configuration, this invokes
ResetToDefaultSelection, which executesSelectOptionand triggers a synchronous call toUpdateAllSelectedcontentsSingle(element)(seehtml_select_element.cc). - This method updates the descendant
<selectedcontent>element by callingCloneContentsFromOptionElement(seehtml_selected_content_element.cc), which executes a synchronous DOM mutation viaReplaceChildrenduring node removal. - The synchronous mutation increments the DOM tree version (
IncDOMTreeVersion()), causingDOMTreeMutationDetector::NeedsRecheck()to returnfalse(seecontainer_node.cc). - Consequently,
RecheckNodeInsertionStructuralPrereq()fails (since the reference node's parent has been mutated), causingmoveBeforeto abort early with aNotFoundErrorexception. - Because the move aborted after the removal phase (which ran while
StatePreservingAtomicMoveInProgresswas true), the skipped detachment operations are never performed. The removed element subtree is left detached but with live layout objects (LayoutObject) and its iframe'sContentFrame()active.
Potential Impact
- Use-After-Free (UAF): The detached subtree retains active
LayoutObjectpointers referencing the original parent's layout tree. If the parent layout tree is subsequently destroyed (for example, by settingdisplay: noneor removing the parent element from the DOM), these layout objects are freed, leaving the detached DOM elements with dangling pointers. Accessing or modifying these detached elements later can trigger a UAF. - Security Invariant Crash: Re-inserting the detached element back into the document triggers
HTMLFrameOwnerElement::InsertedInto(seehtml_frame_owner_element.cc:209). Since the iframe still holds a liveContentFrame()butStatePreservingAtomicMoveInProgress()is nowfalse, this triggers a release-mode security crash (SECURITY_CHECK).
Suggested Reproduction Steps (Potential)
- Construct a DOM structure where an option is a descendant of a moving subtree, containing an iframe and a
<selectedcontent>element sibling:select > button > [selectedcontent > span#ref] + [div#moving > (span > option[selected]) + iframe] - Wait for the iframe to load.
- Call
selectedcontent.moveBefore(moving, ref). - Observe that the call throws a
NotFoundErrorand leavesmovingdetached but with its iframecontentWindownon-null and layout objects active. - Trigger a style/layout recalc on the button/select or set
display: noneto destroy the layout tree. - Access/manipulate the children of
movingto trigger the potential UAF, or appendmovingback to the document to observe the security invariant crash.
Suggested Fix
To mitigate this issue, HTMLOptionElement::RemovedFrom should perform a check for StatePreservingAtomicMoveInProgress() and skip calling OptionRemoved if a state-preserving atomic move is in progress.
Specifically, in third_party/blink/renderer/core/html/forms/html_option_element.cc:
void HTMLOptionElement::RemovedFrom(ContainerNode& insertion_point) {
HTMLElement::RemovedFrom(insertion_point);
if (GetDocument().StatePreservingAtomicMoveInProgress()) {
return;
}
HTMLSelectElement* old_ancestor_select = nearest_ancestor_select_;
...
Evaluated with Chrome root at commit: b1520ef4a76878853a31f0943b565e42060edec8
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, HTMLOptionElement::RemovedFrom calls into select option-removal logic without checking StatePreservingAtomicMoveInProgress, so a synchronous DOM mutation aborts the move after removal but before the skipped detachment work runs.
Impact
The detached subtree could retain dangling layout pointers leading to a use-after-free, or re-insertion could trigger a release-mode security crash; the report notes these are potential findings from static analysis only.
What the attacker needed
Victim loads a crafted page; browser built from affected commit; experimental selectedcontent disabled
The fix
HTMLOptionElement::RemovedFrom should check StatePreservingAtomicMoveInProgress and skip calling OptionRemoved while a state-preserving atomic move is in progress.
How it was found
- Build a DOM where a moving subtree contains an option and an iframe, with a selectedcontent sibling.
- Wait for the iframe to load.
- Call moveBefore on the selectedcontent element with the moving subtree and a reference node.
- Observe the NotFoundError and that the moving subtree is detached but its iframe contentWindow is still non-null.
- Force a layout recalc or hide the parent to destroy the layout tree.
- Access the detached children to trigger the potential use-after-free, or re-append the subtree to hit the security check.
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 moves part of its structure around, the browser normally keeps things consistent. Here the report argues that a piece of code can change the page in the middle of that move, leaving an element that is no longer on the page but still holds references to memory the browser thinks it has cleaned up. Using that stale reference later 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.