Use after free in Messages (CVE-2026-11163)
A use-after-free flaw in the Android HaTS component occurs when a WebContents is destroyed while a survey is pending, leaving a dangling native pointer in the Java peer. An attacker could exploit this to achieve remote code execution in the browser process.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 51 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 without the Chrome Security team.
Overview: A Use-After-Free vulnerability exists in the Android Happiness Tracking Survey (HaTS) component. If a WebContents is destroyed while a survey is pending, the native MessageWrapper object is freed without clearing its Java counterpart's native pointer, leading to a highly exploitable UAF when the survey is eventually interacted with.
Affected files:
chrome/browser/ui/android/hats/hats_service_android.cccomponents/messages/android/message_wrapper.ccchrome/browser/ui/android/hats/java/src/org/chromium/chrome/browser/ui/hats/MessageSurveyUiDelegate.javacomponents/messages/android/java/src/org/chromium/components/messages/MessageWrapper.java
Estimated timestamp from git blame: 2023-09-08
Summary
A precise Use-After-Free (UAF) vulnerability exists in the Android Happiness Tracking Survey (HaTS) component in the browser process.
When a survey is launched (e.g., following a permission prompt), a native C++ messages::MessageWrapper object is created alongside a corresponding Java peer. If the WebContents that triggered the survey is destroyed while the survey payload is asynchronously downloading, the DelayedSurveyTask correctly detects this and destroys the C++ MessageWrapper.
However, because the HaTS Java code enqueues survey messages by directly bypassing the C++ MessageDispatcherBridge, the message_enqueued_ safety flag remains false. This causes the C++ ~MessageWrapper() destructor to skip its safety CHECK and free the memory without clearing the dangling native pointer in the Java peer. When the survey banner is eventually displayed and the user interacts with it (or it auto-dismisses), the Java code invokes JNI callbacks using the dangling pointer, resulting in reliable Remote Code Execution (RCE).
Technical Details
-
Survey Creation:
HatsServiceAndroid::LaunchDelayedSurveyForWebContentscreates aDelayedSurveyTask. This task allocates amessages::MessageWrapper(C++) and invokes JNI to create a matching JavaMessageWrapperobject. The C++thispointer is cast to a rawlongand stored in the Java object'smNativeMessageWrapperfield. -
Asynchronous Download: The Java
SurveyClientImplinitiates an asynchronous download for the survey payload viaSurveyController.downloadSurvey(). During this time, the Java objects are kept alive by callbacks. -
WebContents Destruction: If the
WebContentsis destroyed (e.g., via script callingpopup.close()), theDelayedSurveyTask(aWebContentsObserver) detects this and removes itself viaHatsServiceAndroid::RemoveTask(). This destroys the C++MessageWrapper. -
Bypass of Safety Checks:
- The C++
~MessageWrapper()destructor assertsCHECK(!message_enqueued_);. - Normally,
MessageDispatcherBridgein C++ sets this flag totrue. - However,
MessageSurveyUiDelegate.javaexplicitly callsmMessageDispatcher.enqueueWindowScopedMessage(...)entirely on the Java side. The C++ bridge is bypassed, somessage_enqueued_remainsfalse. - The C++ destructor completes without crashing.
- The C++
-
Dangling Java Pointer: The C++ destructor frees the object memory, but fails to call
Java_MessageWrapper_clearNativePtr(). The JavaMessageWrapper.mNativeMessageWrapperremains populated with a pointer to freed memory. -
UAF and MiraclePtr Bypass: MiraclePtr provides no protection here because the pointer was passed across JNI as a raw
long; there is noraw_ptrto maintain the quarantine reference count. The memory is fully returned to the allocator. -
Exploitation: An attacker can spray the browser heap to reallocate this freed chunk. Once the survey download completes, the banner is displayed. When the user clicks the banner, Java executes
MessageWrapperJni.get().handleActionClick(mNativeMessageWrapper). This enters the C++ methodMessageWrapper::HandleActionClick, which invokesstd::move(action_callback_).Run(). By controlling the reallocated memory, the attacker controls thebase::OnceClosureand hijacks the vtable, achieving sandbox escape and full RCE in the browser process.
Potential Reproduction Steps (Conceptual)
- Host an attacker page that opens a popup window.
- In the popup, trigger a feature that probabilistically qualifies for a HaTS survey (e.g.,
navigator.geolocation.getCurrentPosition()). - The user accepts or denies the prompt, triggering the background survey download.
- The attacker script immediately calls
popup.close()to destroy theWebContentsbefore the download completes. - The attacker script performs a targeted heap spray in the browser process.
- The survey download completes, and the HaTS banner appears on the original opener tab.
- The user clicks the banner, triggering the UAF and executing the attacker's payload.
Suggested Fix
The ~MessageWrapper() destructor must safely inform the Java peer that the native object is being destroyed, regardless of whether the message was enqueued or not. Add Java_MessageWrapper_clearNativePtr(env, java_message_wrapper_); inside the ~MessageWrapper() destructor to ensure the Java-side dangling pointer is always zeroed out upon destruction.
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
The C++ destructor frees the native MessageWrapper without clearing the Java peer's native pointer, because the message_enqueued_ flag was never set when the Java code bypassed the C++ bridge.
Impact
An attacker could achieve remote code execution in the browser process, potentially escaping the sandbox, though the report notes the survey qualification is probabilistic and requires user interaction.
What the attacker needed
Victim visits attacker page; popup window allowed; survey qualifies probabilistically; user interacts with prompt
The fix
The destructor should call Java_MessageWrapper_clearNativePtr to zero the Java-side pointer whenever the native object is destroyed.
How it was found
- Host an attacker page that opens a popup window.
- In the popup, trigger a feature that probabilistically qualifies for a HaTS survey.
- The user accepts or denies the prompt, triggering the background survey download.
- The attacker script immediately calls popup.close() to destroy the WebContents before the download completes.
- The attacker script performs a targeted heap spray in the browser process.
- The survey download completes, and the HaTS banner appears on the original opener tab.
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 frees memory but keeps using it, like deleting a file and still opening it. Here, a survey popup's internal object is freed while the Java side still holds its address, so later clicks use freed memory. An attacker who can control that memory could 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.