Use after free in iOS (CVE-2026-7361)
A potential use-after-free exists in WebStateImpl::RealizedWebState when notifying observers of navigation events, because raw pointers to NavigationContextImpl are passed without validity checks. An attacker could trigger synchronous destruction of the context during observer notification, leading to memory corruption and potentially remote code execution.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 44 days
Flapjack (go/flapjack), an LLM-powered static analysis tool, has identified the following potential security issue.
Overview: A potential Use-After-Free (UAF) exists in WebStateImpl::RealizedWebState when notifying observers of navigation events. If an observer synchronously destroys the NavigationContextImpl (e.g., by disabling web usage), subsequent observers and method accesses use a dangling raw pointer. While OnNavigationStarted mitigates this with a base::WeakPtr check, OnNavigationRedirected and OnNavigationFinished lack this protection, potentially leading to Remote Code Execution (RCE).
Affected files:
ios/web/web_state/web_state_impl_realized_web_state.mm
Estimated timestamp from git blame: 2025-01-23
Summary
A potential Use-After-Free (UAF) vulnerability has been identified in ios/web/web_state/web_state_impl_realized_web_state.mm. When notifying WebStateObservers of navigation events (DidRedirectNavigation, DidFinishNavigation), the code passes a raw pointer to a NavigationContextImpl object. If an observer synchronously triggers an action that causes this context to be destroyed, subsequent access to the pointer results in a UAF.
Technical Details
In WebStateImpl::RealizedWebState, the following methods iterate over observers using a raw NavigationContextImpl* pointer:
-
OnNavigationStarted(NavigationContextImpl* context)(line 272): This method contains a mitigation usingbase::WeakPtr(line 284), gated behind thefeatures::kDetectDestroyedNavigationContextsfeature flag (line 288). If the context is destroyed during the loop, the loop breaks. -
OnNavigationRedirected(NavigationContextImpl* context)(line 296): This method iterates through observers and callsDidRedirectNavigationwithout any checks for the validity of the context between calls. If an observer causes the navigation to be canceled or the web view to be removed, the next observer receives a dangling pointer. -
OnNavigationFinished(NavigationContextImpl* context)(line 303): Similar to the above, it callsDidFinishNavigationwithout aWeakPtrcheck. Crucially, it also accessescontext->IsSameDocument()on line 316 after the observer notification loop has completed.IsSameDocument()is a virtual method. If any observer caused the context's destruction during the loop, this virtual method call on a freed object makes RCE a viable threat.
Potential Trigger Mechanism
NavigationContextImpl objects for pending navigations (including those in the REDIRECTED state or downloads) are owned by CRWWKNavigationStates via a std::unique_ptr. A synchronous destruction of these objects can be triggered by calling WebState::SetWebUsageEnabled(false), which eventually invokes CRWWebController removeWebView.
Here is a potential step-by-step sequence an attacker might use to trigger this vulnerability:
- Initiation: An attacker-controlled web page initiates a navigation (e.g., triggering a server-side redirect or a download).
- State Update:
CRWWKNavigationHandlerupdates the state of the navigation inCRWWKNavigationStatestoREDIRECTEDor leaves it pending. - Observer Notification: The handler invokes
self.webStateImpl->OnNavigationRedirected(context)orself.webStateImpl->OnNavigationFinished(context), passing the raw pointer toWebStateImpl. - Looping Observers: Execution enters
WebStateImpl::RealizedWebStateand begins iterating overWebStateObserverobjects. - Synchronous Destruction: During this iteration, an observer synchronously triggers an action that disables web usage for the
WebState(e.g., viaWebUsageEnablerBrowserAgent::SetWebUsageEnabled(false)). This calls[web_controller_ setWebUsageEnabled:NO], which calls[self removeWebView]. - Pending Navigations Cleared: Inside
removeWebView, the code explicitly iterates over all pending navigations and calls[self.navigationHandler.navigationStates removeNavigation:navigation]. - Memory Freed:
[CRWWKNavigationStates removeNavigation:]removes the navigation record and releases itsstd::unique_ptr<web::NavigationContextImpl>. The context is destroyed and freed. - Use-After-Free: Execution returns to the observer loop in
WebStateImpl::RealizedWebState. Thecontextparameter is now a dangling pointer. - Subsequent Access: The loop continues to the next observer, passing the dangling pointer. Furthermore, if this occurred in
OnNavigationFinished, the code evaluatescontext->IsSameDocument()on the freed object. BecauseIsSameDocument()is virtual, this dereferences a hijacked vtable pointer.
Note: The LLM agent does not have the ability to run code or build a working PoC, so these steps are suggested/potential based on static analysis.
Impact
As ios/web runs within the main browser process on iOS, this Use-After-Free vulnerability allows for memory corruption. Because it involves a virtual method call (IsSameDocument()) on a synchronously freed object, an attacker could potentially overwrite the memory via heap spraying and hijack the control flow, leading to full Remote Code Execution (RCE) and a sandbox escape.
Evaluated with Chrome root at commit: 43c4f3945742db6f06efbaf9a77b90f34a720277
Results from Flapjack so far have been promising, but it can be wrong in its deductions. At this time, it does not produce proof of concepts or fuzzer tests. If this proves to be a false positive, please close as WAI; data from false positives will be used to improve Flapjack’s 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 passes raw pointers to NavigationContextImpl to observer callbacks without using weak pointers or checking validity, so if an observer synchronously destroys the context, subsequent accesses become use-after-free.
Impact
Because ios/web runs in the main browser process, this use-after-free could allow memory corruption and, via a virtual method call on freed memory, potentially lead to remote code execution and a sandbox escape.
What the attacker needed
Attacker-controlled web page; observer that synchronously disables web usage; iOS browser process
The fix
The code should be fixed by adding weak pointer checks or other validity checks in OnNavigationRedirected and OnNavigationFinished, similar to the mitigation already present in OnNavigationStarted.
How it was found
- An attacker-controlled web page initiates a navigation (e.g., triggering a server-side redirect or a download).
- CRWWKNavigationHandler updates the navigation state to REDIRECTED or leaves it pending.
- The handler invokes OnNavigationRedirected or OnNavigationFinished, passing the raw pointer to WebStateImpl.
- Execution enters WebStateImpl::RealizedWebState and begins iterating over WebStateObserver objects.
- During iteration, an observer synchronously disables web usage, which calls removeWebView and clears pending navigations, freeing the NavigationContextImpl.
- Execution returns to the observer loop with a dangling pointer, and OnNavigationFinished later calls context->IsSameDocument() on the freed object.
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, during a navigation event, the code tells observers about the event but does not check if the navigation data still exists. If an observer causes that data to be deleted, later code uses the freed memory, which can crash the app 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.