Insufficient validation of untrusted input in WebShare (CVE-2026-9977)
The Android WebShare API's Java implementation lacks validation for the SafeBaseName Mojo type, allowing a compromised renderer to bypass filename checks and write arbitrary files into the browser process's private directories. This could lead to a sandbox escape by writing a malicious file to a location accessible via FileProvider.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 18 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. Please see https://chromium.googlesource.com/chromium/src/+/main/docs/security/ai-generated-security-bugs-faq.md for more information.
Overview: The Android WebShare API is potentially vulnerable to path traversal because the SafeBaseName Mojo type lacks Java-side validation. A compromised renderer can bypass filename checks to write arbitrary files into the browser process's FileProvider-exported directories. This occurs because Mojo pipes are forwarded directly to Java, skipping the validation traits defined in C++.
Affected files:
components/browser_ui/webshare/android/java/src/org/chromium/components/browser_ui/webshare/ShareServiceImpl.javachrome/browser/chrome_browser_interface_binders.ccmojo/public/mojom/base/BUILD.gnthird_party/blink/public/mojom/webshare/webshare.mojom
Estimated timestamp from git blame: 2022-11-07
Vulnerability Details
The WebShare API on Android is potentially vulnerable to a path traversal attack that allows a compromised renderer process to write files in the browser process's private data directory.
The vulnerability stems from a lack of validation for the SafeBaseName Mojo type in the Java implementation of ShareService. The SharedFile struct in webshare.mojom uses SafeBaseName for filenames, which is intended to represent a path component without directory separators or .. components.
In C++, SafeBaseName is protected by StructTraits (in mojo/public/cpp/base/safe_base_name_mojom_traits.cc) that enforce these constraints during deserialization. However, on Android, the ShareService Mojo pipe is forwarded directly to Java via ForwardToJavaWebContents in chrome_browser_interface_binders.cc. Because there is no Java typemap for SafeBaseName defined in mojo/public/mojom/base/BUILD.gn, the Java bindings deserialize it as a raw struct, and the validation logic in the C++ traits is completely bypassed.
In ShareServiceImpl.java, the isDangerousFilename method performs insufficient validation on the resulting string:
static boolean isDangerousFilename(String name) {
// Reject filenames without a permitted extension.
return name.indexOf('.') <= 0
|| !PERMITTED_EXTENSIONS.contains(FileUtils.getExtension(name));
}
An attacker can bypass this check by providing a path starting with a slash and containing traversal components, such as /../../../../cache/webapks/evil.html. In this scenario:
name.indexOf('.')returns 1 (the first dot), so the checkindexOf('.') <= 0evaluates tofalse.FileUtils.getExtension(name)successfully parses the string and extractshtml, which is a permitted extension, making the second conditionfalse.
The method incorrectly assumes the filename is safe. When ShareServiceImpl creates the temporary file for sharing, it uses the following logic:
tempFile = new File(tempDir, file.name.path.path);
On Android's Unix-style filesystem, if the child path provided to the File(File, String) constructor starts with a /, it concatenates the child path to the parent path. This allows an attacker to use .. components to escape the intended tempDir. For example, if tempDir is /data/user/0/com.android.chrome/files/images/screenshot/share123/, the resulting path resolves to /data/user/0/com.android.chrome/cache/webapks/evil.html.
Potential Exploit Scenario
Note: These are suggested steps, as we do not have a working proof of concept that has been successfully run.
- An attacker compromises the renderer process (e.g., via a V8 vulnerability).
- The attacker crafts a
blink::mojom::ShareService::ShareMojo IPC message. - The attacker populates the
SharedFilestruct, setting thenamefield to/../../../../cache/webapks/evil.htmland providing a malicious payload in theblobfield. - The
cache/webapks/directory is deliberately chosen because it corresponds to<cache-path name="webapk" path="webapks/" />infile_paths.xml. This ensures the subsequent call toFileProviderUtils.getContentUriFromFile(tempFile)succeeds without throwing anIllegalArgumentException. - The browser process processes the request, bypassing
SafeBaseNamechecks, creating the file in the cache directory, and writing the attacker's payload to it.
This constitutes an arbitrary file write within the browser process's filesystem, representing a sandbox escape.
Suggested Fix
- Implement a proper Java typemap and validation for the
SafeBaseNameMojo type to ensure consistency with the C++StructTraits. - Update
ShareServiceImpl.isDangerousFilenameto explicitly reject strings containing directory separators (/or\) or traversal components (..).
Evaluated with Chrome root at commit: eca8648a4e1cdfdda68c495a6003059fed641955
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 bindings for the SafeBaseName Mojo type do not perform the same validation as the C++ StructTraits, and the Java filename check is insufficient to block path traversal.
Impact
A compromised renderer could write arbitrary files within the browser process's filesystem, potentially escaping the sandbox.
What the attacker needed
Compromised renderer process; ability to send Mojo IPC messages
The fix
Implement a Java typemap with validation for SafeBaseName and strengthen the filename check to reject directory separators and traversal components.
How it was found
- Compromise the renderer process (e.g., via a V8 vulnerability).
- Craft a ShareService::Share Mojo IPC message.
- Set the SharedFile name to a path with traversal components and a permitted extension.
- Choose a target directory that is exported via FileProvider (e.g., cache/webapks/).
- Send the message; the browser process writes the file to the attacker-chosen location.
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 security check meant to stop file names from escaping a folder is missing in one part of Chrome for Android. If an attacker can already run code inside a restricted part of the browser, they could use this gap to write files anywhere the browser can, potentially breaking out of that restriction.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.