Use after free in WebView (CVE-2026-7342)
A use-after-free exists in the js_injection::JsBinding class because it uses a raw Mojo receiver that remains active after the object is marked dead by Oilpan's garbage collector. An attacker could trigger synchronous JavaScript execution during an IPC handler to force a nested garbage collection that frees the object while its member function is still running, potentially leading to remote code execution in the renderer.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 12 days
Flapjack, 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. Please see https://chromium.googlesource.com/chromium/src/+/main/docs/security/ai-generated-security-bugs-faq.md for more information.
Overview: js_injection::JsBinding is an Oilpan-managed object that uses a raw Mojo receiver, allowing IPC messages to be dispatched to a logically dead object. Synchronous JavaScript execution during the IPC handler can force a nested garbage collection cycle that destroys the object while its member function is active, leading to a highly exploitable Use-After-Free.
Affected files:
components/js_injection/renderer/js_binding.cccomponents/js_injection/renderer/js_binding.h
Estimated timestamp from git blame: 2023-10-25
Summary
A potential Use-After-Free (UAF) vulnerability exists in the js_injection::JsBinding class in the renderer process. The class is managed by Oilpan (cppgc) but uses a raw mojo::AssociatedReceiver, which lacks awareness of Oilpan's lifecycle. This allows Mojo messages to be dispatched to a logically dead object. An attacker can exploit this by triggering synchronous JavaScript execution that forces the object to be swept while it is executing on the call stack.
Vulnerability Details
The js_injection::JsBinding class inherits from gin::Wrappable<JsBinding>, making its lifetime managed by Chromium's Oilpan garbage collector (cppgc). It hosts a mojo::AssociatedReceiver<mojom::BrowserToJsMessaging> member (receiver_) which is bound to this to handle IPC messages from the browser.
In Chromium's Oilpan system, garbage collection uses "lazy sweeping". When an object becomes unreachable, it is marked as dead during the atomic pause, but its C++ destructor is deferred until the sweeping phase reclaims the memory later. Because JsBinding uses a raw Mojo receiver and does not have a pre-finalizer to unbind it during the atomic pause, a race condition exists: the receiver remains active and bound to the IPC pipe even after the object is marked dead.
Exploitation Steps (Theoretical)
An attacker could potentially trigger this vulnerability using the following steps:
- Setup: The attacker uses JavaScript to register an
onmessagecallback on the injected JS object, and adds a dummy event listener to populate thelisteners_vector. - Orphan the Object: The attacker drops all JavaScript references to the object and forces a garbage collection cycle.
- Marking & Handle Clearing:
cppgcidentifies theJsBindingobject as unreachable. V8'sTracedHandles::ResetDeadNodesclears thewrapper_reference. The object is logically dead but itsmojo::AssociatedReceiverremains active pending lazy sweeping. - IPC Dispatch: The Browser process sends an
OnPostMessageIPC. Mojo dispatches this to the active receiver, callingJsBinding::OnPostMessagewith thethispointer referencing the logically dead memory. - Synchronous JS Execution: Inside
OnPostMessage, the code safely generates a new wrapper (aswrapper_.IsEmpty()is true) and synchronously executes the attacker'son_message_callback viaPausableScriptExecutor::CreateAndRun(..., EvaluationTiming::kSynchronous). - Nested GC & Synchronous Sweeping: Inside the JS callback, the attacker forces massive allocations to trigger a new GC cycle. In
cppgc, starting a new GC cycle explicitly callssweeper_.FinishIfRunning(). This forces the synchronous execution of the previous cycle's destructors on the main thread, including~JsBinding(). The memory forthisis freed. - Heap Spraying: The attacker immediately allocates a new
cppgcobject of the same size, overlapping the newly freedJsBindingmemory and forging the internal pointers of thelisteners_vector. - Use-After-Free: The JS callback returns.
OnPostMessageresumes and attempts to accesslisteners_.size()and iterate over the vector (listeners_copy.reserve(listeners_.size());). This reads from the attacker-controlled overlapped memory.
Because MiraclePtr (BackupRefPtr) protects PartitionAlloc but does not protect the cppgc managed heap, this UAF can be reliably transformed into an arbitrary memory read/write primitive, leading to Remote Code Execution (RCE) in the renderer process.
Fix Recommendations
- Primary Fix: Replace the raw
mojo::AssociatedReceiverwithHeapMojoAssociatedReceiver(orHeapMojoReceiverif the interface is updated). Heap Mojo wrappers arecppgc-aware and automatically disconnect when the owner object is marked dead, preventing dispatch to a dying object. - Alternative Fix: Add the
USING_PRE_FINALIZERmacro toJsBindingto explicitly callreceiver_.reset()during the pre-finalization phase (the atomic pause), before lazy sweeping begins.
Evaluated with Chrome root at commit: c0eb5541aebfa4ea08806eaf6e94bcc69f87ab2f
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
The JsBinding object is managed by Oilpan but uses a raw Mojo receiver that is not unbound when the object is marked dead, so IPC messages can still be dispatched to it after it is logically dead.
Impact
This UAF could be reliably transformed into an arbitrary memory read/write primitive, leading to Remote Code Execution (RCE) in the renderer process, because MiraclePtr does not protect the cppgc managed heap.
What the attacker needed
Ability to run JavaScript in a WebView; browser sends an IPC message to the object
The fix
Replace the raw Mojo receiver with a HeapMojoAssociatedReceiver that is cppgc-aware and automatically disconnects when the owner is marked dead, or add a pre-finalizer to reset the receiver during the atomic pause.
How it was found
- Register an onmessage callback on the injected JS object and add a dummy event listener.
- Drop all JavaScript references to the object and force a garbage collection cycle.
- The object is marked unreachable and its wrapper reference is cleared, but the Mojo receiver remains active.
- The browser sends an OnPostMessage IPC that is dispatched to the still-active receiver.
- Inside the handler, the attacker's onmessage callback runs synchronously and forces a nested garbage collection that frees the object.
- The attacker sprays the heap to overlap the freed memory, and when the handler resumes it reads from attacker-controlled 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.
This report describes a memory safety bug in a web browser component. The object that handles messages from the browser to injected JavaScript can be freed from memory while it is still being used, because the garbage collector does not immediately clean up dead objects. An attacker who can run JavaScript in the page could exploit this to take control of the browser process.
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.