Use after free in Headless (CVE-2026-13832)
A use-after-free exists in the headless shell's browser context disposal routine, which iterates over a snapshot of raw pointers to web contents. Closing one target can synchronously destroy another target still held in that snapshot, so the loop later calls Close() on a freed object, which could crash the browser process.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 46 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 Use-After-Free vulnerability in headless_shell can be triggered when a browser context is disposed of while containing specifically configured DevTools sessions. The issue arises from iterating over a snapshot of raw pointers to WebContents that can be synchronously destroyed during the iteration process.
Affected files:
headless/lib/browser/headless_devtools_manager_delegate.ccheadless/lib/browser/headless_web_contents_impl.ccheadless/lib/browser/headless_browser_context_impl.ccheadless/lib/browser/protocol/target_handler.ccheadless/lib/browser/protocol/headless_devtools_session.cc
Estimated timestamp from git blame: 2025-04-02
Summary
A Use-After-Free (UAF) vulnerability exists in the HeadlessDevToolsManagerDelegate::DisposeBrowserContext function. The vulnerability is triggered when closing one HeadlessWebContents synchronously causes the destruction of another HeadlessWebContents that is also present in a local snapshot vector of raw pointers.
Root Cause Analysis
In headless/lib/browser/headless_devtools_manager_delegate.cc, the DisposeBrowserContext method snapshots the current WebContents into a std::vector<HeadlessWebContents*>:
void HeadlessDevToolsManagerDelegate::DisposeBrowserContext(
content::BrowserContext* browser_context, DisposeCallback callback) {
// ...
std::vector<HeadlessWebContents*> web_contents = context->GetAllWebContents();
while (!web_contents.empty()) {
for (auto* wc : web_contents)
wc->Close(); // Potential UAF here
web_contents = context->GetAllWebContents();
}
// ...
}
The wc->Close() call eventually leads to the synchronous destruction of the HeadlessWebContentsImpl object. If the destruction of one object (A) synchronously triggers the destruction of another object (B) that is also in the web_contents vector, the iteration will reach a dangling pointer when it attempts to call Close() on B.
Synchronous Destruction Chain
This condition can be reached using the Chrome DevTools Protocol (CDP). A DevTools session (Session A) can "own" other targets if they are created as "hidden" targets through that session. When Target A is closed:
- Target A is destroyed, which synchronously destroys its associated DevTools sessions (including Session A).
- The destructor of
HeadlessDevToolsSessioncallsTargetHandler::Disable(). TargetHandler::Disable()iterates over itshidden_web_contents_and callsClose()on them (e.g., Target B).- If Target B's renderer is crashed (not live), the Content layer (
RenderFrameHostImpl::ClosePage) executes the closure synchronously, immediately destroying Target B.
When control returns to the loop in DisposeBrowserContext, the pointer to Target B is dangling, leading to a UAF upon the next virtual call to Close().
Potential Reproduction Steps
Note: These steps are suggested based on code analysis; our environment does not support functional execution of proof-of-concept code.
- Launch
chrome-headless-shellwith DevTools enabled (e.g.,--remote-debugging-pipe). - Create a new
BrowserContext(Context X) via CDP. - Create a target (Target A) in Context X and attach to it to obtain a session.
- Using the session for Target A, create a hidden target (Target B) in Context X using
Target.createTarget({hidden: true}). - Crash the renderer process for Target B (e.g., by navigating it to
chrome://crash). - Call
Target.disposeBrowserContextfor Context X. - The browser process should encounter a UAF when the disposal loop reaches the destroyed Target B.
Suggested Fix
The snapshot should not store raw pointers to objects with managed lifetimes. Instead, use a vector of base::WeakPtr<HeadlessWebContentsImpl> and verify that the pointer is still valid before calling Close() in each iteration. Alternatively, iterate over a list of Target IDs and re-resolve them in each step.
// Suggested remediation using WeakPtr
std::vector<base::WeakPtr<HeadlessWebContentsImpl>> web_contents_weak;
for (auto* wc : context->GetAllWebContents()) {
web_contents_weak.push_back(HeadlessWebContentsImpl::From(wc)->GetWeakPtr());
}
for (auto& wc_weak : web_contents_weak) {
if (wc_weak) {
wc_weak->Close();
}
}
Evaluated with Chrome root at commit: 1a8d40fc44df2088d5945c0bf53584038aa1614a
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
Likely the disposal loop snapshots raw pointers to web contents whose lifetimes are managed elsewhere, and a synchronous destruction chain triggered by closing one target frees another target still referenced in the snapshot.
Impact
The browser process could encounter a use-after-free, which may crash it; the text does not claim code execution or any other impact.
What the attacker needed
Headless shell with DevTools enabled; ability to create and crash targets via CDP
The fix
The snapshot should hold weak pointers (or target identifiers re-resolved each round) and check validity before calling Close(), though the text does not say a fix was applied.
How it was found
- Launch the headless shell with DevTools enabled.
- Create a new browser context through the DevTools protocol.
- Create a target in that context and attach a session to it.
- From that session, create a hidden target in the same context.
- Crash the hidden target's renderer, for example by navigating it to a crash page.
- Dispose the browser context and observe the use-after-free in the browser process.
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 a program frees an object but keeps a pointer to it and later uses that pointer, this is called a use-after-free. Here the browser takes a list of open pages, then closes them one by one; closing one page can also close another page on the same list, leaving a stale entry. Using that stale entry can crash the browser.
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.