Use after free in Search (CVE-2026-78937)
A use-after-free flaw in Chrome for Android's search engine settings allows a malicious webpage to trigger a dangling pointer dereference, potentially leading to arbitrary memory read in the browser process. An attacker could exploit this by registering multiple OpenSearch engines and manipulating their visit order to cause a cached Java wrapper to reference freed C++ memory.
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 browser process on Chrome for Android when updating search engines via OpenSearch. The SearchEngineAdapter Java UI cache retains a raw JNI pointer to a TemplateURL that can be freed when a duplicate engine is added in the background, leading to a UAF read that bypasses MiraclePtr during UI refreshes.
Affected files:
chrome/browser/search_engines/android/java/src/org/chromium/chrome/browser/search_engines/settings/SearchEngineAdapter.javacomponents/search_engines/android/template_url_android.cccomponents/search_engines/template_url_service.cccomponents/search_engines/android/java/src/org/chromium/components/search_engines/TemplateUrl.java
Estimated timestamp from git blame: 2026-01-20
Summary
On Android, the SearchEngineAdapter (used for the 'Settings → Search engine' list) maintains a cache of TemplateUrl Java wrappers to represent recent and prepopulated search engines. Each Java wrapper holds a raw C++ pointer (long mTemplateUrlPtr) to its underlying TemplateURL object in the browser process.
When a TemplateURL is destroyed in the C++ backend—such as when it is automatically replaced by a newer OpenSearch Description Document (OSDD) engine with the same keyword—the Java observer is notified asynchronously. However, the update logic in SearchEngineAdapter performs a comparison between the new search engine list and the old cached list before updating its cache. This comparison invokes JNI methods on the cached wrappers, resulting in a Use-After-Free (UAF) dereference of the freed C++ TemplateURL pointer.
Because the reference is stored as a raw long on the Java heap, this vulnerability bypasses MiraclePtr (BackupRefPtr) protections.
Potential Exploitation Steps
The following sequence outlines how an attacker could potentially trigger this vulnerability:
- The attacker crafts a web page that registers 4 distinct OSDD engines by injecting
<link rel="search" type="application/opensearchdescription+xml" href="osdd1.xml">tags. - In the renderer,
ChromeRenderFrameObserverdetects these tags and sends a Mojo message to the browser process, which downloads and adds the engines (E1, E2, E3, E4) toTemplateURLService. - The attacker's webpage triggers background navigations to the search endpoints of E1, E2, E3, and E4. The Chrome History service updates their
last_visitedtimestamps. The attacker spaces these so the visit recency is ordered: E4 > E3 > E2 > E1. - The victim is persuaded to open Chrome Settings and navigate to the "Search engine" section. The Java
SearchEngineAdapterinitializes and callsrefreshData(). refreshData()retrieves the engines, sorts them bylast_visited, and keeps at mostMAX_RECENT_ENGINE_NUM(3). It retains E4, E3, and E2, while E1 is filtered out. The JavaTemplateUrlwrappers for E4, E3, and E2 (holding raw C++ pointers) are cached inmRecentSearchEngines.- While the Settings page remains open, the attacker's web page injects a 5th OSDD file (E5) configured with the same search keyword as E2.
TemplateURLService::Add(E5)is called. It uses aScoperto temporarily suppress observer notifications and callsRemoveDuplicateReplaceableEnginesOf(E5).RemoveDuplicateReplaceableEnginesOffinds the conflicting engine E2. Because E5 was created more recently, E5 is deemed "better".TemplateURLService::Remove(E2)is called, which destroys thestd::unique_ptr<TemplateURL>. The C++ memory is freed. The BRP refcount reaches 0 because the only remaining reference is the rawlongin the Java heap.- The
Scopergoes out of scope, triggeringOnTemplateURLServiceChangednotifications. SearchEngineAdapter.onTemplateURLServiceChanged()callsrefreshData(). It retrieves the new list: E1, E3, E4, and E5.- E5 is filtered out because it has never been visited (
last_visitedis 0). The new list of recent engines is exactly 3: E4, E3, and E1. refreshData()callsdidSearchEnginesChange(newList). Because the old list had 3 engines and the new list has 3 engines, it bypasses the early return and proceeds to an element-wise comparison.- It calls
containsTemplateUrl(mRecentSearchEngines, E1). This iterates over the old list, which contains the stale wrapper for E2. - The comparison invokes
E2.getIsPrepopulated()andE2.getKeyword(). These calls cross the JNI boundary and cast the danglinglongback to aTemplateURL*, dereferencing the freed memory. base::android::ConvertUTF16ToJavaStringreads the underlying UTF-16 character data using thestring_viewderived from the attacker-controlled memory layout, resulting in an arbitrary memory read in the Browser process.
Suggested Fix
To prevent this UAF and safely manage the lifecycle of the C++ object across the JNI boundary, the design should be updated so that Java does not hold raw pointers to memory it doesn't own.
Potential fixes include:
- Use
base::android::ScopedJavaGlobalRef: Have the C++TemplateURLobject own a global reference to its Java counterpart. When the C++ object is destroyed, it can explicitly invalidate or clear the pointer inside the Java wrapper, preventing subsequent JNI calls from dereferencing a stale pointer. - Pass Data by Value: Instead of caching wrappers with raw pointers, pass the required display data (keyword, short name, prepopulated ID) to Java by value when
getTemplateUrlsis called. The Java side would then compare these value objects rather than invoking native methods during the UI refresh loop.
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 Java SearchEngineAdapter caches raw pointers to C++ TemplateURL objects without proper ownership tracking, so when the C++ object is freed, the Java side still holds a dangling pointer that is dereferenced during UI refresh comparisons.
Impact
A malicious webpage could cause a use-after-free read in the browser process, potentially leading to arbitrary memory read or a crash, though the report does not demonstrate full exploitation.
What the attacker needed
Victim uses Chrome for Android; victim visits attacker's webpage; victim opens search engine settings; attacker can register OpenSearch engines
The fix
The design should be updated so that Java does not hold raw pointers to memory it doesn't own, for example by using ScopedJavaGlobalRef or passing data by value.
How it was found
- The attacker crafts a web page that registers 4 distinct OSDD engines by injecting link tags.
- The attacker's webpage triggers background navigations to the search endpoints of E1, E2, E3, and E4, spacing them so visit recency is ordered E4 > E3 > E2 > E1.
- The victim opens Chrome Settings and navigates to the 'Search engine' section, causing SearchEngineAdapter to cache the top 3 recent engines (E4, E3, E2).
- While the Settings page remains open, the attacker's web page injects a 5th OSDD file (E5) with the same search keyword as E2.
- TemplateURLService::Add(E5) removes the duplicate E2, freeing its C++ memory, and then notifies observers.
- SearchEngineAdapter.onTemplateURLServiceChanged() calls refreshData(), which compares the new list against the old cached list, dereferencing the freed E2 pointer.
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 Chrome on Android. When you open the search engine settings, the app keeps a list of search engines in memory. If a malicious website adds a new search engine that replaces an existing one, the old engine's memory is freed, but the settings screen still holds a pointer to it. Later, when the screen refreshes, it tries to read the freed memory, which could crash the browser or leak data.
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.