Use after free in Views (CVE-2026-79140)
A use-after-free exists in the macOS browser process because a range-based for loop over a mutable vector can be invalidated when a nested run loop processes a task that deletes a child window. An attacker who can queue such a task could cause the loop to dereference a freed object, potentially leading to arbitrary code execution.
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 potential Use-After-Free (UAF) exists in the macOS browser process due to iterator invalidation in NativeWidgetNSWindowBridge::OrderChildren. A synchronous nested run loop allows task execution that can mutate the child_windows_ vector during a range-based for loop iteration. Resuming the loop dereferences a dangling pointer, potentially leading to arbitrary code execution.
Affected files:
components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mmui/views/cocoa/native_widget_mac_ns_window_host.mmui/views/widget/native_widget_mac.mmcomponents/remote_cocoa/app_shim/views_nswindow_delegate.mm
Estimated timestamp from git blame: 2023-07-07
Description
A potential Use-After-Free (UAF) vulnerability exists in the macOS implementation of NativeWidgetNSWindowBridge::OrderChildren.
When a window's visibility changes (e.g., from an AppKit windowDidDeminiaturize: callback), OrderChildren iterates over the child_windows_ vector using a C++ range-based for loop (for (auto* child : child_windows_)). A range-based for loop caches the end iterator of the vector before the loop begins.
During iteration, if a child window is a modal sheet, the code calls child->ShowAsModalSheet(). For in-process Mac windows, this synchronously invokes the native macOS API -[NSWindow beginSheet:completionHandler:]. This native method spins a nested run loop to handle the sheet animation.
Because the call stack originated directly from a native OS AppKit callback and not from within a standard Chrome task loop, Chrome's re-entrancy protection (task_execution_allowed_ being set to false in DoWorkImpl) is bypassed. The nested message pump will process pending Chrome application tasks.
If one of these pending tasks closes another child window attached to the same parent, that child window is deleted and erased from the child_windows_ vector. This vector mutation shrinks the logical size of the vector, invalidating the cached end iterator of the paused range-based for loop.
When the nested run loop exits and the iteration resumes, the loop reads past the new logical end of the vector, fetching a stale raw pointer from the vector's capacity buffer. This dangling pointer points to the newly freed child window object. The loop then reads member variables from this freed object (child->wants_to_be_visible(), child->window_) and passes the attacker-controlled NSWindow* to [window addChildWindow:child_window ordered:NSWindowAbove], providing a strong primitive for Remote Code Execution (RCE) in the unsandboxed browser process.
Suggested Reproduction Steps
Note: These are suggested/potential steps to trigger the vulnerability. Our tooling agent does not yet have the ability to run code to verify them dynamically.
- Open a standard browser window on macOS (ensuring an in-process NativeWidgetNSWindowBridge).
- Trigger the creation of two child windows on this parent: a modal dialog (e.g., a certificate selector) and a standard bubble (e.g., a permission prompt).
- Minimize the parent window. The modal sheet is queued to be shown but remains hidden because the parent is minimized.
- Queue a malicious task or Mojo IPC message that will close the standard bubble when executed.
- Restore (deminiaturize) the parent window.
- The OS invokes
windowDidDeminiaturize:, leading toOrderChildren. OrderChildrenprocesses the modal dialog and calls-[NSWindow beginSheet:], spinning the nested run loop.- The queued task executes during the nested loop, destroying the standard bubble and erasing it from
child_windows_. - The nested loop returns, the range-based for loop resumes with an invalid iterator, and a UAF occurs.
Suggested Fix
Avoid iterating directly over the mutable child_windows_ vector if the loop body can spin a nested run loop.
Since NativeWidgetNSWindowBridge supports base::WeakPtr (via its factory_), a safe approach is to create a local vector of weak pointers to the children before iterating:
std::vector<base::WeakPtr<NativeWidgetNSWindowBridge>> children_copy;
children_copy.reserve(child_windows_.size());
for (auto* child : child_windows_) {
children_copy.push_back(child->GetWeakPtr());
}
for (auto& weak_child : children_copy) {
if (!weak_child)
continue;
// ... existing loop logic ...
}
This ensures that if a child is destroyed during the nested run loop, the weak pointer will safely evaluate to null when the iteration resumes.
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 code iterates over a mutable vector with a range-based for loop while the loop body can synchronously spin a nested run loop that mutates the vector, invalidating the cached end iterator.
Impact
An attacker could potentially achieve arbitrary code execution in the unsandboxed browser process, though the report notes the reproduction steps are suggested and not yet verified.
What the attacker needed
MacOS browser process; ability to queue a task or IPC message; parent window with two child windows; victim restores minimised window
The fix
The code should avoid iterating directly over the mutable vector when the loop body can spin a nested run loop, for example by copying weak pointers to the children before iterating.
How it was found
- Open a standard browser window on macOS with an in-process NativeWidgetNSWindowBridge.
- Create two child windows on the parent: a modal dialog and a standard bubble.
- Minimise the parent window so the modal sheet is queued but hidden.
- Queue a task or IPC message that will close the standard bubble when executed.
- Restore the parent window to trigger windowDidDeminiaturize and OrderChildren.
- OrderChildren calls beginSheet, spinning a nested run loop; the queued task deletes the bubble, and the loop resumes with an invalid iterator causing a UAF.
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 use-after-free happens when a program keeps using a piece of memory after it has been freed. Here, a loop over a list of child windows pauses while the system runs other tasks, and one of those tasks removes an item from the list. When the loop resumes, it reads a stale pointer to the removed item, which can crash the browser or 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.