Use after free in Extensions (CVE-2026-12445)
A time-of-check to time-of-use flaw in the userScripts.execute() API lets a malicious extension bypass permission checks when a target frame navigates cross-origin during an asynchronous file load. This poisons the browser-side ScriptInjectionTracker, allowing a compromised renderer to impersonate the extension and access its private data and APIs.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 34 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: A Time-of-Check to Time-of-Use (TOCTOU) vulnerability in the userScripts.execute() API allows a malicious extension to bypass permission checks when a target frame navigates cross-origin during a script file load. This results in the irreversible poisoning of the browser-side ScriptInjectionTracker for the victim process, potentially allowing a compromised renderer to impersonate the extension and access its private data and APIs.
Affected files:
extensions/browser/api/user_scripts/user_scripts_api.ccextensions/browser/script_executor.ccextensions/browser/extension_api_frame_id_map.ccextensions/browser/script_injection_tracker.cc
Estimated timestamp from git blame: 2025-01-09
Description
A Time-of-Check to Time-of-Use (TOCTOU) vulnerability exists in the userScripts.execute() extension API (introduced in extensions/browser/api/user_scripts/user_scripts_api.cc). The vulnerability occurs because the API validates target-frame permissions before performing an asynchronous file load but fails to re-validate them before proceeding with the script injection.
Root Cause Analysis
In UserScriptsExecuteFunction::Run(), the API first validates whether the extension has permission to inject scripts into the target frames using scripting::CanAccessTarget(). If the injection involves files, it initiates an asynchronous file load via scripting::CheckAndLoadFiles(). The results of the initial permission check, including the target frame_ids and a raw ScriptExecutor*, are bound into the callback DidLoadResources().
During the window between the initial permission check and the completion of the file load, a target frame can navigate to a different (cross-origin) site. When DidLoadResources() eventually runs, it proceeds to call Execute() and then scripting::ExecuteScript() using the stale frame_ids without re-verifying permissions against the current state of the frames.
Inside the ScriptExecutor::Handler (which manage the injection), the browser re-resolves the integer frame_id to its current RenderFrameHost using ExtensionApiFrameIdMap::GetRenderFrameHostById(). This method uses an unsafe lookup that returns the current RenderFrameHost for the frame tree node, even if it has navigated cross-process.
Impact: ScriptInjectionTracker Poisoning
Before the execution IPC is sent to the renderer, the browser calls ScriptInjectionTracker::WillExecuteCode(). This call irreversibly marks the RenderProcessHost associated with the victim frame as having executed a script from the extension.
Even if the renderer-side security checks (e.g., ProgrammaticScriptInjector::CanExecuteOnFrame()) later block the actual script execution because the extension lacks host permission for the new origin, the browser-side poisoning has already occurred.
An attacker with a compromised renderer in the victim process can then leverage this state to bypass several browser-side security gates, such as CanRendererActOnBehalfOfExtension(). This allows the compromised renderer to:
- Invoke extension APIs restricted to content/user script contexts (e.g.,
chrome.storage). - Open messaging channels to the extension's background page.
- Access sensitive data or privileges granted to the extension's scripts.
Secondary Issue: Potential Use-After-Free
UserScriptsExecuteFunction::Run() binds a raw ScriptExecutor* to the DidLoadResources callback. Since ScriptExecutor is typically owned by a TabHelper associated with a WebContents, closing the tab during the asynchronous file load will result in a dangling pointer. When DidLoadResources or Execute eventually dereferences this pointer, it will cause a Use-After-Free (UAF) crash in the browser process.
Suggested Reproduction Steps
Note: These are potential steps as our analysis is based on code review.
- Install an extension with the
userScriptspermission and host permission forhttps://attacker.example/*. Ensure Developer Mode is enabled. - Create a tab with a subframe at
https://attacker.example/sub. - Trigger
chrome.userScripts.execute()targeting the subframe's ID, requesting a large script file from the extension to maximize the race window. - While the file load is pending in the browser, navigate the subframe to a sensitive cross-origin site (e.g.,
https://victim.example/). - Observe that
ScriptInjectionTracker::WillExecuteCode()is called for thevictim.exampleprocess despite the extension lacking permissions for that origin. - (Post-poisoning) Verify that a compromised renderer in the
victim.exampleprocess can successfully invoke restricted extension APIs by claiming the identity of the attacker's extension.
Recommended Fix
Follow the safe pattern implemented in scripting.executeScript (see extensions/browser/api/scripting/scripting_api.cc):
- Do not bind
ScriptExecutor*orframe_idsacross the asynchronous file load boundary. - In
DidLoadResources, re-invokescripting::CanAccessTarget()to re-verify permissions and re-acquire a validScriptExecutorand set of target frames before proceeding withscripting::ExecuteScript().
Evaluated with Chrome root at commit: b3153093eb3c78c3e88ccf562bcbc20437a04b0e
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 API validates target-frame permissions before an asynchronous file load but does not re-validate them before injecting the script, and it binds a raw ScriptExecutor pointer and stale frame IDs across the asynchronous boundary.
Impact
A compromised renderer in the victim process could bypass browser-side security gates to invoke extension APIs, open messaging channels to the extension's background page, and access sensitive data or privileges granted to the extension's scripts; the text notes that renderer-side checks may still block actual script execution, but the browser-side poisoning already occurred.
What the attacker needed
Malicious extension with userScripts permission; host permission for attacker's site; Developer Mode enabled; victim frame navigates cross-origin during load
The fix
The fix should follow the safe pattern in scripting.executeScript: do not bind ScriptExecutor* or frame_ids across the asynchronous file load, and re-invoke scripting::CanAccessTarget() in DidLoadResources to re-verify permissions and re-acquire a valid ScriptExecutor and target frames before…
How it was found
- Install an extension with the userScripts permission and host permission for the attacker's site, with Developer Mode enabled.
- Create a tab with a subframe on the attacker's site.
- Trigger chrome.userScripts.execute() targeting the subframe and requesting a large script file to widen the race window.
- While the file load is pending, navigate the subframe to a sensitive cross-origin site.
- Observe that ScriptInjectionTracker::WillExecuteCode() is called for the victim site's process despite lacking permissions.
- Verify that a compromised renderer in the victim process can invoke restricted extension APIs by claiming the attacker's extension identity.
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.
When an extension asks the browser to run a script in a web page, the browser first checks if the extension is allowed to touch that page. But if the page changes to a different website while the script file is still loading, the browser forgets to check again. This means the browser wrongly believes the extension ran code on the new site, which can let a compromised part of the browser pretend to be that extension and steal its data.
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.