Use after free in Views (CVE-2026-79128)
A use-after-free exists in the macOS app_shim process because an Objective-C block captures a raw this pointer and is posted to a task runner; if the Mojo pipe disconnects before the block runs, the object is deleted and the block dereferences freed memory. An attacker who compromises a PWA renderer could potentially trigger this to achieve remote code execution in the unsandboxed app_shim process.
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 unsandboxed app_shim process. An Objective-C block in NativeWidgetNSWindowBridge::ShowAsModalSheet implicitly captures a raw this pointer and is posted to the task runner. If the Mojo pipe is disconnected before the block executes, the bridge is destroyed, leading to a UAF that could potentially be exploited for Remote Code Execution.
Affected files:
components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mmcomponents/remote_cocoa/app_shim/application_bridge.mmcomponents/remote_cocoa/app_shim/native_widget_ns_window_bridge.h
Estimated timestamp from git blame: 2024-03-28
Summary
A potential Use-After-Free (UAF) vulnerability exists in the macOS app_shim process within the NativeWidgetNSWindowBridge::ShowAsModalSheet method. The vulnerability arises because an Objective-C block implicitly captures the raw C++ this pointer by value. When the block is posted to a task runner and delayed, a race condition can allow the NativeWidgetNSWindowBridge instance to be deleted before the block executes, leading to a UAF.
Because the app_shim process on macOS operates without a sandbox (switches::kAppShimProcessType maps to Sandbox::kNoSandbox), successful exploitation of this memory corruption could yield full user privileges (Remote Code Execution).
Technical Details
In components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm, the ShowAsModalSheet() method prepares an Objective-C block (begin_sheet_closure) to display a modal sheet:
auto begin_sheet_closure = base::BindOnce(^{
[parent_window beginSheet:window_
completionHandler:^(NSModalResponse return_code) {
// ...
wants_to_be_visible_ = false;
OnWindowWillClose();
}];
});
Inside this block, the code accesses the class member variable window_ and within the nested completionHandler, it accesses wants_to_be_visible_ and calls the member function OnWindowWillClose(). In Objective-C++, referencing member variables or functions inside a block implicitly captures the C++ this pointer by value as a raw pointer.
When running in an out-of-process App Shim (e.g., a PWA), host_helper_->MustPostTaskToRunModalSheetAnimation() returns true (see NativeWidgetBridgeOwner in application_bridge.mm). Consequently, ShowAsModalSheet posts begin_sheet_closure to the UI thread's task runner rather than executing it synchronously.
Potential Exploitation Steps
Note: These are suggested steps; our tooling agent does not have the ability to run code to verify an end-to-end exploit.
- An attacker compromises a PWA renderer process or creates a malicious PWA.
- The attacker's JavaScript triggers an action that causes the browser to show a window-modal dialog (e.g.,
navigator.subApps.add()). - The browser process sends a
SetVisibilityState(kShow)Mojo message to theapp_shimprocess. - Immediately after triggering the modal, the attacker cancels the dialog or closes the parent window, causing the browser to close the
mojom::NativeWidgetNSWindowMojo pipe. - The
app_shim's IO thread receives both the visibility message and the pipe disconnection notification sequentially, posting them to the UI thread's task queue. - The UI thread executes the visibility task, routing to
ShowAsModalSheet(). This creates the block capturing the rawthispointer and appends it as a new task to the end of the UI thread's queue. - The UI thread then executes the Mojo disconnect task. This calls
NativeWidgetBridgeOwner::OnMojoDisconnect(), which executesdelete this;, destroying theNativeWidgetNSWindowBridgeand freeing its memory. - The attacker sprays the heap via other IPC messages, aiming to reclaim the freed
NativeWidgetNSWindowBridgememory with attacker-controlled data. - The UI thread finally executes the delayed
begin_sheet_closuretask. The block dereferences the implicitly captured, now-freedthispointer. - If the memory was successfully reclaimed, the attacker-controlled data is passed to
[NSWindow beginSheet:]. When AppKit attempts to send an Objective-C message to this corrupted object, it jumps to an attacker-controlled address, leading to RCE in the unsandboxedapp_shimprocess.
Since the captured this pointer is a raw C++ pointer and not explicitly a base::raw_ptr<T>, MiraclePtr protection does not mitigate this vulnerability.
Suggested Fix
To prevent the UAF, use base::WeakPtr to safely capture a reference to the NativeWidgetNSWindowBridge instance inside the Objective-C block. If the object is destroyed before the block executes, the weak pointer will be safely nullified.
base::WeakPtr<NativeWidgetNSWindowBridge> weak_this = factory_.GetWeakPtr();
auto begin_sheet_closure = base::BindOnce(^{
if (!weak_this) {
return;
}
[parent_window beginSheet:weak_this->window_
completionHandler:^(NSModalResponse return_code) {
if (!weak_this) {
return;
}
weak_this->wants_to_be_visible_ = false;
weak_this->OnWindowWillClose();
}];
});
(Note: factory_ must be added to NativeWidgetNSWindowBridge if it does not already exist).
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
An Objective-C block implicitly captures a raw this pointer and is posted asynchronously, so the object can be destroyed before the block executes.
Impact
If the freed memory is reclaimed with attacker-controlled data, this could lead to remote code execution with full user privileges in the unsandboxed app_shim process; the report notes the steps are suggested and not verified end-to-end.
What the attacker needed
MacOS app_shim process; attacker compromises a PWA renderer; or attacker creates a malicious PWA; ability to trigger a window-modal dialog
The fix
The report suggests capturing a base::WeakPtr to the bridge inside the block and checking it before use, so the block safely does nothing if the object has been destroyed.
How it was found
- An attacker compromises a PWA renderer or creates a malicious PWA.
- The attacker's JavaScript triggers a window-modal dialog.
- The browser sends a SetVisibilityState(kShow) Mojo message to the app_shim process.
- The attacker cancels the dialog or closes the parent window, closing the Mojo pipe.
- The app_shim posts the visibility task and the disconnect task to the UI thread queue.
- The UI thread runs the visibility task, which posts the block, then runs the disconnect task, which deletes the bridge, and finally runs the block on 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 use-after-free is a memory bug where a program keeps a pointer to an object after that object has been deleted, then later uses the pointer as if the object still existed. Here, a delayed task holds a raw pointer to a window bridge object; if the object is destroyed before the task runs, the task touches freed memory. Because the affected process runs without a sandbox, an attacker who can control that freed memory might 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.