Inappropriate implementation in MHTML (CVE-2026-8012)
MHTML generation shared one file handle across all renderer processes in a frame tree without enforcing append-only writes, so a compromised cross-origin subframe could truncate and rewrite the file. This let an attacker forge the whole MHTML archive, giving a persistent Site Isolation bypass and UXSS, notably on Android Offline Pages.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 41 days
Project Fortify, an experimental security project, has identified the following potential security issue.
Overview: MHTML generation shares a single file handle across all renderer processes in a frame tree without enforcing append-only writes. A compromised cross-origin subframe can use its duplicated handle to truncate the file and rewind the shared seek offset, erasing the main frame's content. This allows the attacker to forge the entire MHTML archive, leading to a persistent Site Isolation bypass and Universal Cross-Site Scripting (UXSS), especially critical on Android's automated Offline Pages.
Affected files:
content/browser/download/mhtml_generation_manager.cccontent/renderer/mhtml_handle_writer.ccchrome/browser/offline_pages/offline_page_mhtml_archiver.ccchrome/browser/offline_pages/recent_tab_helper.cc
Estimated timestamp from git blame: 2019-04-04
Description
There is a potential vulnerability in Chrome's MHTML generation logic where a single file handle is shared across all renderers in a frame tree. In content/browser/download/mhtml_generation_manager.cc, CreateMHTMLFile opens a file with base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE. It does not use base::File::FLAG_APPEND.
To serialize each frame, the browser process calls mojom::MhtmlOutputHandle::NewFileHandle(browser_file_.Duplicate()) and sends this duplicated handle to the corresponding renderer process via the SerializeAsMHTML Mojo method.
On Windows and POSIX systems (excluding Fuchsia), base::File::Duplicate() uses DuplicateHandle() or dup(). These OS-level functions create a new descriptor that points to the exact same underlying kernel open-file description. Consequently, all renderer processes and the browser process share the same global file seek offset.
Because the main frame is processed first, it writes the top-level MHTML headers and its content to the file. However, when a cross-origin subframe receives its duplicated handle, it has full write access to the entire file. A compromised renderer can issue ftruncate(fd, 0) and lseek(fd, 0, SEEK_SET)—both of which are explicitly permitted by the Linux/Android seccomp-bpf sandbox for legitimately obtained file descriptors (sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc). The attacker can then overwrite the file with a forged MHTML archive containing malicious scripts, attributing them to the main frame's origin.
Impact
This is a Site Isolation bypass resulting in persistent cross-origin spoofing and UXSS. The impact is particularly severe on Android, where RecentTabHelper automatically triggers background MHTML saves for 'Offline Pages' when tabs are hidden. An attacker can silently poison the offline cache of a trusted victim site without any user interaction.
Potential Exploitation Steps
Note: These are suggested steps based on code analysis. Our setup does not execute code to verify these steps with a working proof of concept.
- Setup: An attacker embeds a cross-origin subframe (
attacker.com) inside a trusted page (victim.com). The attacker uses a separate vulnerability (e.g., a V8 bug) to compromise the sandboxed renderer process hostingattacker.com. - Trigger: An MHTML save is initiated (e.g., automatically by Android's Offline Pages when the user switches tabs, or manually via 'Save Page As').
- Main Frame Serialization: The browser creates the file and sends a duplicated handle to the
victim.comrenderer, which writes legitimate MHTML headers and content. The shared file offset advances. - Subframe Interception: The browser duplicates the handle again and sends it to the
attacker.comrenderer, along with themhtml_boundary_markerinsidemojom::SerializeAsMHTMLParams. - Truncate and Rewind: The compromised
attacker.comrenderer intercepts the Mojo call, extracts the file descriptor (fd), and executesftruncate(fd, 0)followed bylseek(fd, 0, SEEK_SET). - Payload Injection: Using the provided boundary marker, the attacker writes a fully forged MHTML payload to
fd. The forged payload claims to bevictim.comand contains malicious scripts. - Finalization: The browser appends the MHTML footer. The resulting file is a well-formed archive entirely controlled by the attacker.
- Execution: When the user opens the file or views the offline page, the attacker's scripts execute in the context of
victim.com.
Suggested Fix
There are two primary ways to fix this:
- Enforce Append-Only Writes: Modify the file creation in
MHTMLGenerationManager::CreateMHTMLFileto usebase::File::FLAG_APPENDinstead ofbase::File::FLAG_WRITE. On POSIX, this maps toO_APPEND, ensuring that all writes automatically occur at the end of the file, regardless of anylseek()calls by a compromised renderer. - Use Data Pipes: Transition the architecture to use Mojo Data Pipes instead of raw file descriptors. The
MhtmlOutputHandleunion already supports aproducer_handle(mojo::ScopedDataPipeProducerHandle), and the renderer side has an implementation (MHTMLProducerHandleWriter). Updating the browser side to use this pipe would eliminate the shared kernel file description entirely.
Evaluated with Chrome root at commit: 0eb4855bda702feaaa8b899336664f97e3df88b8
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. Please feel free to reach out to me if you have concerns or feedback.
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 file is opened with create-and-write flags rather than append-only, and duplicated descriptors share one kernel file offset, so any renderer holding a handle can truncate and rewind the shared file.
Impact
This is a Site Isolation bypass leading to persistent cross-origin spoofing and UXSS, and on Android an attacker could silently poison the offline cache of a trusted site without user interaction; the steps are unverified code analysis, and the attack requires a separate renderer compromise first.
What the attacker needed
Attacker page embedded as a subframe; separate renderer compromise (e.g. V8 bug); an MHTML save is triggered; Android Offline Pages for silent poisoning
The fix
It should be fixed by opening the file append-only so writes always land at the end, or by replacing raw file descriptors with Mojo data pipes.
How it was found
- Embed a cross-origin subframe inside a trusted page and compromise that subframe's renderer.
- Trigger an MHTML save, for example automatically via Android Offline Pages or manually via Save Page As.
- The browser sends a duplicated handle to the main frame renderer, which writes legitimate headers and content.
- The browser sends another duplicated handle to the attacker renderer along with the boundary marker.
- The attacker renderer truncates the file and rewinds the shared offset, then writes a forged archive claiming the victim origin.
- The browser appends the footer, and the forged archive executes the attacker's scripts in the victim's context when opened.
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 Chrome saves a page as a single MHTML file, it hands each part of the page (each frame) a way to write into that same file. The mistake is that every frame gets the same write position and can also shrink the file back to nothing. A malicious frame could therefore wipe the real page content and write its own, so the saved file looks like it came from the trusted site.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.