Race in MHTML (CVE-2026-7351)
A time-of-check to time-of-use race exists between the pageCapture.saveAsMHTML extension API and MHTMLGenerationManager. An extension could race an asynchronous file creation task with a fast BFCache navigation to make the browser serialise the DOM of a restricted page, bypassing origin checks.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 27 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 security team.
Overview: A Time-of-Check to Time-of-Use (TOCTOU) vulnerability exists between the chrome.pageCapture.saveAsMHTML API and MHTMLGenerationManager. An extension can race an asynchronous file creation task by triggering a fast BFCache restoration navigation, tricking the browser into serializing the DOM of a restricted page instead of the authorized one.
Affected files:
content/browser/download/mhtml_generation_manager.ccchrome/browser/extensions/api/page_capture/page_capture_api.cc
Estimated timestamp from git blame: 2024-09-04
Summary
A Time-of-Check to Time-of-Use (TOCTOU) vulnerability exists in the MHTMLGenerationManager when combined with the chrome.pageCapture.saveAsMHTML extension API.
The saveAsMHTML API performs a permission check and verifies the target document's ID before initiating MHTML generation. However, MHTMLGenerationManager::Job::initializeJob captures only the persistent FrameTreeNodeIds of the page before posting an asynchronous task to a background thread to create the target file (CreateMHTMLFile).
While the background task is executing, an attacker can trigger a fast navigation, such as restoring a restricted page (e.g., chrome://settings) from the Back/Forward Cache (BFCache). When the file creation task finishes and execution resumes on the UI thread, MHTMLGenerationManager::Job::SendToNextRenderFrame fetches the current_frame_host() for each captured FrameTreeNodeId. Because the BFCache navigation has already committed, the job will instruct the restricted page's RenderFrameHost to serialize its DOM, bypassing the extension API's origin checks and exfiltrating sensitive data.
Technical Details
PageCaptureSaveAsMHTMLFunction::Run()checks permissions and saves theDocumentId(document_id_) of the authorized page.- After creating a temporary file,
TemporaryFileCreatedOnUIverifies that the current main frame'sDocumentIdstill matchesdocument_id_. If so, it callsWebContents::GenerateMHTML(). MHTMLGenerationManager::Job::initializeJob()takes a snapshot of the frame tree by storingFrameTreeNodeIds intopending_frame_tree_node_ids_.initializeJob()posts an asynchronous task toGetDownloadTaskRunner()to callCreateMHTMLFile.- During this task hop, a fast navigation (e.g., a BFCache restore) can commit on the UI thread, swapping the document in the main frame's
FrameTreeNode. - The background task completes, and
MHTMLGenerationManager::Job::OnFileAvailableresumes on the UI thread. SendToNextRenderFrame()is called. It pops aFrameTreeNodeIdand callsftn->current_frame_host(). This now returns the newly restoredRenderFrameHost(the restricted page).- The browser calls
writer_->SerializeAsMHTML()on the restrictedRenderFrameHost. The renderer process does not perform URL or permission checks and serializes the restricted DOM.
Potential Steps to Reproduce
Note: These steps are suggested based on code analysis; a working PoC has not yet been executed.
- A malicious extension (with
pageCapturepermission) opens a tab to a restricted URL likechrome://settings. - The extension navigates the tab away to an attacker-controlled origin (
https://attacker.com), placingchrome://settingsinto the BFCache. - The extension calls
chrome.pageCapture.saveAsMHTML({tabId: ...}). - Immediately after, the extension triggers a fast navigation back to the restricted page:
chrome.tabs.goBack(...). - The BFCache restoration commits quickly, racing the background file creation task (
CreateMHTMLFile). - The MHTML generation process completes using the newly restored document.
- The extension reads the resulting MHTML file to access the DOM of
chrome://settings.
Suggested Fix
Instead of storing persistent FrameTreeNodeIds, MHTMLGenerationManager::Job should store GlobalRenderFrameHostIds or the DocumentId for each frame during initializeJob. When iterating in SendToNextRenderFrame(), the job should verify that the RenderFrameHost still matches the saved ID before proceeding with serialization. Alternatively, the job should abort if a navigation occurs while it is pending.
Evaluated with Chrome root at commit: ff3d2b74fa39431785bd60e51463b08fcc71ee33
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
Impact
An extension with pageCapture permission could read the DOM of restricted pages such as chrome://settings, bypassing the API's origin checks; the report notes that a working proof of concept has not yet been executed.
What the attacker needed
Malicious extension with pageCapture permission; ability to trigger BFCache restore navigation; timing the race correctly
The fix
The job should store GlobalRenderFrameHostIds or DocumentIds and verify they still match before serialising, or abort if a navigation occurs while it is pending.
How it was found
- A malicious extension with pageCapture permission opens a tab to a restricted URL.
- The extension navigates the tab away to an attacker-controlled origin, placing the restricted page into the BFCache.
- The extension calls chrome.pageCapture.saveAsMHTML for that tab.
- Immediately after, the extension triggers a fast navigation back to the restricted page.
- The BFCache restoration commits quickly, racing the background file creation task.
- The MHTML generation completes using the newly restored document, and the extension reads the file to access the restricted DOM.
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 to save a page as an MHTML file, the browser first checks that the extension is allowed to access that page. But the browser then does some slow work in the background. If the page changes during that time, the browser may end up saving the new page without re-checking permissions. Here, an attacker could make the page change to a restricted internal page, so the extension saves content it should never see.
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.