Use after free in WebView (CVE-2026-3936)
A use-after-free flaw exists in the JsCommunication component of Chromium's WebView when injected JavaScript removes an iframe during script execution. An attacker could exploit this to cause a crash and potentially achieve remote code execution.
- Fix shipped in 34 days
Steps to reproduce the problem
Tested on Pixel 9 Pro, Chromium version 144.0.7559.109.
- Build
app.zipand Install python -m http.server- Visit
index.html - UAF and Crash
Problem Description
JsCommunication is a content::RenderFrameObserver, which is destructed along with the destruction of the RenderFrameImpl [1].
On iOS and Android platforms, application developers can use interfaces (such as addDocumentStartJavaScript) to inject JavaScript code that runs at DocumentEnd or DocumentStart. JavaScript injected through this interface also runs in iframes. When the JavaScript executes, the scripts in the vector are processed one by one in a for-loop[2],[3].
void JsCommunication::OnDestruct() {
delete this; // [1]
}
void JsCommunication::RunScripts(mojom::DocumentInjectionTime injection_time) {
url::Origin frame_origin =
url::Origin(render_frame()->GetWebFrame()->GetSecurityOrigin());
for (const auto& script : scripts_) { // [2]
if (!script->origin_matcher.Matches(frame_origin)) {
continue;
}
if (script->injection_time == injection_time) {
if (script->js_world == content::ISOLATED_WORLD_ID_GLOBAL) {
render_frame()->GetWebFrame()->ExecuteScript(
blink::WebScriptSource(script->script));
} else {
render_frame()->GetWebFrame()->ExecuteScriptInIsolatedWorld( // [3]
script->js_world, blink::WebScriptSource(script->script),
blink::BackForwardCacheAware::kAllow);
}
}
}
}
The injected JavaScript can easily be redirected to code controlled by an attacker, for example, through getter, setter, or redefining functions in the prototype. An attacker can then remove the iframe, causing the RenderFrameImpl to be destroyed, which in turn destroys the JsCommunication object. When the next loop attempts to execute JavaScript, a UAF occurs, which is not protected by miraclePtr
Although triggering this UAF requires certain preconditions, in practice, many browsers (such as the Pawxy browser) utilize this interface, and it is also widely used by third-party libraries (e.g., react-native-webview).
app.zipis a simple WebView-based browser that injects two JavaScript codes via theaddDocumentStartJavaScriptinterface.
private void injectStartUpScripts() {
if (WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT)) {
Set<String> allowedOriginRules = Collections.singleton("*");
try {
WebViewCompat.addDocumentStartJavaScript(
webView,
"console.log(`${new Number(1.1)}`);",
allowedOriginRules
);
// WebViewCompat.addDocumentStartJavaScript(
// webView,
// "console.log(global_value)",
// allowedOriginRules
// );
WebViewCompat.addDocumentStartJavaScript(
webView,
"console.log('Second Script Injected');",
allowedOriginRules
);
} catch (Exception e) {
Log.e(TAG, "addDocumentStartJavaScript failed");
}
} else {
Toast.makeText(this, "addDocumentStartJavaScript not supported", Toast.LENGTH_SHORT).show();
}
}
- Using this browser to visit the attacker’s webpage.
- The attacker’s webpage redefines
Number.prototype.toStringinside an iframe.
node.contentWindow.Number.prototype.toString = function () {
node.remove();
};
- The first injected JavaScript executes and triggers the attacker’s code, which removes the iframe, ultimately leading to the destruction of
JsCommunication. - In the next iteration of the loop, a UAF occurs.
Summary
UAF in JsCommunication, leading to RCE
Custom Questions
Reporter credit:
Am4deu$
Additional Data
Category: Security
Chrome Channel: Stable
Regression: N/A \
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 JsCommunication object is deleted when its RenderFrameImpl is destroyed, but the loop iterating over injected scripts continues to use the deleted object without a check.
Impact
The use-after-free could lead to remote code execution, though the report notes that triggering it requires certain preconditions.
What the attacker needed
Victim uses a WebView app with injected scripts; victim visits attacker-controlled page; app uses addDocumentStartJavaScript
How it was found
- Build and install a WebView-based browser app that injects two JavaScript snippets via addDocumentStartJavaScript.
- Start a local HTTP server and visit the attacker's index.html page.
- The attacker's page redefines Number.prototype.toString inside an iframe to remove the iframe.
- The first injected script runs and triggers the attacker's code, removing the iframe and destroying JsCommunication.
- On the next loop iteration, a use-after-free occurs and the browser crashes.
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 bug where a program deletes an object from memory but then tries to use it again, which can let an attacker control what happens next. Here, a browser feature that injects JavaScript into web pages can be tricked into deleting an iframe while still running scripts, causing the browser to crash and possibly run attacker 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.