Race Safe Browsing (CVE-2026-12022)
A time-of-check to time-of-use flaw in macOS Safe Browsing lets a compromised sandboxed helper replace a temporary file with a symbolic link before the browser copies data to that path. The browser then follows the link and writes attacker-controlled content to a target outside the sandbox with the browser's privileges.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 16 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. Please see https://chromium.googlesource.com/chromium/src/+/main/docs/security/ai-generated-security-bugs-faq.md for more information.
Overview: A potential Time-of-Check to Time-of-Use (TOCTOU) vulnerability exists in the macOS Safe Browsing implementation of BinaryFeatureExtractor. By creating a temporary file in a shared directory, closing its file descriptor, and subsequently copying data to the path using symlink-following APIs, Chrome may allow a compromised sandboxed helper process to swap the file with a symbolic link. This could potentially enable an attacker to perform arbitrary file writes with the privileges of the unsandboxed browser process.
Affected files:
chrome/common/safe_browsing/binary_feature_extractor.ccbase/files/file_util_apple.mm
Estimated timestamp from git blame: 2023-02-07
Root Cause Analysis
In BinaryFeatureExtractor::ExtractImageFeatures (located in chrome/common/safe_browsing/binary_feature_extractor.cc), a temporary file is created using base::CreateTemporaryFile:
base::FilePath temp_path;
if (!base::CreateTemporaryFile(&temp_path)) {
return false;
}
if (!base::CopyFile(file_path, temp_path)) {
base::DeleteFile(temp_path);
return false;
}
Under the hood, base::CreateTemporaryFile calls mkstemp() and immediately closes the returned file descriptor, returning only the file path (temp_path) to the caller. This introduces a Time-of-Check to Time-of-Use (TOCTOU) window before the file is reopened or written to.
Subsequently, base::CopyFile(file_path, temp_path) is called to copy the downloaded file into the temporary path. On macOS, base::CopyFile is implemented in base/files/file_util_apple.mm using the system copyfile(3) function with only the COPYFILE_DATA flag. It lacks the COPYFILE_NOFOLLOW_DST flag, meaning the system copy function will follow symbolic links at the destination path.
Trust Boundary & Shared Directory Access
On macOS, the temporary directory returned by NSTemporaryDirectory() points to the per-user temporary directory _CS_DARWIN_USER_TEMP_DIR located inside /var/folders/.
Several sandboxed helper processes (such as the Network Service, GPU process, and On-Device Model Execution service) are granted write/unlink access within this directory via the Seatbelt sandbox parameter darwin-user-temp-dir:
- Network Service (
sandbox/policy/mac/network.sb):(allow file-read* file-write* (subpath (param darwin-user-temp-dir))) - GPU Process (
sandbox/policy/mac/gpu.sb):(allow file-read* file-write-data file-write-create file-write-owner file-write-unlink (subpath (param darwin-user-temp-dir))) - On-Device Model Execution (
sandbox/policy/mac/on_device_model_execution.sb):(allow file-read* file-write* (subpath (param darwin-user-temp-dir)))
Because both the unsandboxed browser process and the compromised sandboxed helper processes run with the exact same macOS User ID (UID), they have matching discretionary access control permissions over files in this shared directory.
Potential Exploitation Scenario
An attacker who has already compromised a sandboxed helper process (such as the Network Service or GPU process) could potentially execute the following steps to escape the sandbox:
- Monitor: The compromised process monitors the shared
darwin-user-temp-dirfor the creation of files matching Chrome's temp file prefix pattern (e.g.,.com.google.Chrome.XXXXXX). - Delete: Immediately after
base::CreateTemporaryFilecreates the file and closes its file descriptor, the compromised process callsunlink()on the temporary file path to delete it. - Symlink: The compromised process immediately calls
symlink()to create a symbolic link attemp_pathpointing to a target file outside the sandbox (e.g.,~/Library/LaunchAgents/com.pwn.plist). - Write (Sandbox Escape): When the unsandboxed browser process calls
base::CopyFile, the macOS kernel follows the symbolic link attemp_pathand writes the contents of the downloaded binary directly into the target plist file with the privileges of the browser process. This allows for persistent execution outside the sandbox.
Note: These steps are based on static analysis and represent potential exploitation vectors; our tooling does not yet have the capability to execute code or verify this via a live proof-of-concept.
Suggested Fix
Avoid closing the temporary file and reopening/writing to it by path. Instead, keep the file descriptor open after creation (for example, by utilizing base::CreateAndOpenTemporaryFileInDir) and write to the file descriptor directly rather than using path-based APIs. If path-based file copying is necessary, ensure that safe flags such as COPYFILE_NOFOLLOW_DST are used on macOS, or verify that the destination is not a symbolic link before writing.
Evaluated with Chrome root at commit: b1520ef4a76878853a31f0943b565e42060edec8
Results so far have been promising, but there can be wrong deductions. Feel free to adjust as follows:
- If you are familiar with the severity guidelines, you may adjust the severity.
- If this is a false positive, and there's no work to be done, please close as WAI.
- If there is work to do here but not a vulnerability, please change the issue type to Task/Bug/FR.
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 temporary file is created and its file descriptor closed, then the path is reused with a copy operation that follows symbolic links at the destination.
Impact
A compromised sandboxed helper could write arbitrary files with the browser's privileges, potentially achieving persistent execution outside the sandbox; the report notes this is based on static analysis and has not been verified with a live proof-of-concept.
What the attacker needed
Compromised sandboxed helper process; macOS; shared per-user temporary directory
The fix
Keep the temporary file descriptor open and write through it, or use safe flags such as COPYFILE_NOFOLLOW_DST and verify the destination is not a symbolic link.
How it was found
- Monitor the shared temporary directory for files matching Chrome's temp file prefix.
- Delete the temporary file after its descriptor is closed.
- Create a symbolic link at the temporary path pointing to a target outside the sandbox.
- Let the browser copy data to the path, which follows the link and writes to the target.
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 temporary file is created and its handle is closed, leaving only the file path. A malicious helper process sharing the same folder can delete that file and put a shortcut (symbolic link) in its place. When the browser later writes to the path, it follows the shortcut and writes to a file it should not touch.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.