# MHTML

**MHTML**（MIME HTML）是一种网页归档格式，在 RFC 2557 中被标准化为“MIME 封装聚合文档，如 HTML”，它将一个完整网页——包括其 HTML 根文档以及它所引用的图像、样式表、脚本和其他资源——打包成一个单一的 MIME 多部分文件，用于电子邮件传输、离线查看或归档。<sup>[1](https://datatracker.ietf.org/doc/html/rfc2557)</sup> 文件通常带有 .mhtml 或 .mht 扩展名。<sup>[2](https://www.file-extension.info/format/mhtml)</sup>

| 关键事实 | 详情 |
|---|---|
| 标准 | RFC 2557，提议标准，1999 年 3 月；取代 RFC 2110（1997 年 3 月）<sup>[1](https://datatracker.ietf.org/doc/html/rfc2557)</sup> |
| 容器 | 一个 MIME multipart/related 消息，包含一个 text/html 根正文部分和每个附属资源各一个正文部分<sup>[1](https://datatracker.ietf.org/doc/html/rfc2557)</sup> |
| 链接机制 | Content-Location 内容头让 HTML 根文档中的 URI 可以引用同一结构中的其他正文部分<sup>[1](https://datatracker.ietf.org/doc/html/rfc2557)</sup> |
| 编码 | 资源以 base64 或 quoted-printable 编码；Content-Location 头保留原始 URL<sup>[3](https://formats.jarhalab.com/formats/mhtml)</sup> |
| 浏览器支持 | Internet Explorer 原生保存和打开 .mht；Chrome 和 Edge 可打开 .mhtml/.mht；Firefox 无原生支持；Safari 改用 .webarchive<sup>[3](https://formats.jarhalab.com/formats/mhtml)</sup> |
| 替代方案 | Safari .webarchive、SingleFile 单 HTML 文件、WARC、MAFF，以及“网页，完整”HTML 加资源文件夹<sup>[3](https://formats.jarhalab.com/formats/mhtml)</sup> |

## 目的与标准化

浏览器获取的 HTML 文档很少是单个文件：text/html 根资源通过 URI 引用图像、视频片段和小程序等附属资源，每个资源都单独获取。要在单封电子邮件中传输这样的文档，需要两样东西：一种将根文档及其附属资源聚合为一个复合消息结构的方法，以及一种让根文档中的 URI 引用该结构内部资源的方法。RFC 2557 用 MIME multipart/related 内容类型解决了第一个问题，用 Content-Location 头解决了第二个问题。<sup>[1](https://datatracker.ietf.org/doc/html/rfc2557)</sup>

这项工作始于 IETF MHTML 工作组，由 Einar A. Stefferud 担任主席，斯德哥尔摩大学/瑞典皇家理工学院的 Jacob Palme 和微软的 Alex Hopmann 担任编辑。该工作组产出了三项提议标准，即 RFC 2110、2111 和 2112，允许在 MIME multipart/related 正文部分中传输复合网页文档；RFC 2112 定义了 multipart/related 本身。<sup>[4](https://datatracker.ietf.org/wg/mhtml/about/)</sup> RFC 2110 于 1997 年 3 月发布，定义了 Content-Location 和用于解析相对 URI 的 Content-Base 头。<sup>[5](https://datatracker.ietf.org/doc/html/rfc2110)</sup> RFC 2557 于 1999 年 3 月取代了它。<sup>[1](https://datatracker.ietf.org/doc/html/rfc2557)</sup>

尽管是为电子邮件设计的，该规范指出，同样的约定也可用于通过 HTTP 或 FTP 在单次传输中获取完整的多资源文档，或用于完整 HTML 文档的存储和归档。<sup>[1](https://datatracker.ietf.org/doc/html/rfc2557)</sup>

## 文件结构

MHTML 文件是一个 MIME 编码的消息，结构上类似于带附件的已保存电子邮件。<sup>[6](https://archiveexplorer.com/formats/mht)</sup> 它以 From、Subject、Date 和 MIME-Version 等消息头开头，随后是一个 multipart/related 正文，各部分由边界字符串分隔。第一部分是 text/html 根文档，带有一个包含页面原始 URL 的 Content-Location 头；后续部分保存每个附属资源，各自带有自己的 Content-Type、Content-Transfer-Encoding（base64 或 quoted-printable）和 Content-Location。<sup>[3](https://formats.jarhalab.com/formats/mhtml)</sup>

在渲染 text/html 正文部分时，读取器会针对一个基准解析标记中的每个 URI，依次采用以下第一个适用项：正文部分内部指定的基准地址，如 HTML BASE 元素；所属头部的 Content-Location 头中的绝对 URI；或递归地，外层 multipart 或 message 头部中的 Content-Location。<sup>[1](https://datatracker.ietf.org/doc/html/rfc2557)</sup> 与另一个正文部分的 Content-Location 匹配的 URI 将从该部分提供，而不是通过网络获取，这正是该文件能够自包含的原因。<sup>[1](https://datatracker.ietf.org/doc/html/rfc2557)</sup>

## 浏览器支持与历史

**微软 Internet Explorer** 推广了这种格式。微软于 1997 年在 [Internet Explorer](https://www.edgepedia.org/zh/internet-explorer) 4.0 中引入了将网页保存为单个文件的功能，最初使用专有格式，而 IE 的“网页档案，单一文件（.mht）”保存选项使 .mht 成为离线保存网页的常见方式。<sup>[2](https://www.file-extension.info/format/mhtml)</sup> 在 IE 中，渲染 MHTML 页面实际上使用的是 [Outlook Express](https://www.edgepedia.org/zh/outlook-express) 中实现的 MHTML URL 处理器，而非浏览器本身的代码。<sup>[7](https://learn.microsoft.com/en-us/security-updates/securitybulletins/2003/ms03-014)</sup>

**Chromium 浏览器**可以打开 .mhtml 和 .mht 文件，Chrome 的“页面另存为”可以生成 MHTML；2012 年针对“页面另存为 MHTML”功能的一次代码审查指出，生成的文件在全部四种操作系统上的 Chrome 以及 Opera 中均可查看，但在 [Firefox](https://www.edgepedia.org/zh/firefox)、Safari 或当时的 IE 中则不行。<sup>[8](https://codereview.chromium.org/10069014)</sup> Firefox 没有原生支持，但有扩展可用，而 Safari 改用其自己的 .webarchive 格式，即 Apple 二进制属性列表。<sup>[3](https://formats.jarhalab.com/formats/mhtml)</sup> 微软 Edge 保留了对本地 .mht 和 .mhtml 文件的处理能力，包括一项控制它们是否在 Internet Explorer 模式下自动打开的策略。<sup>[9](https://learn.microsoft.com/en-us/deployedge/microsoft-edge-browser-policies/internetexplorerintegrationlocalmhtfileallowed)</sup>

## 安全性

由于 MHTML 文件是一个从多个来源重新组装内容的本地文档，浏览器会对其施加限制。例如，WebKit 出于安全原因仅从本地文件系统加载 MHTML 页面。<sup>[10](https://bugs.webkit.org/show_bug.cgi?id=86540)</sup> 当 Chromium 将页面保存为 MHTML 时，其 FrameSerializer 会通过移除 onload 等脚本属性来净化 DOM，并有意剥离原始文档的 [Content Security Policy](https://www.edgepedia.org/zh/content-security-policy) 头和元标签，以便子资源正确加载。<sup>[11](https://issues.chromium.org/issues/503865896)</sup> 已有净化缺陷的报告：一个区分大小写的属性过滤器允许通过 DOM API 注入的混合大小写 ONLOAD 属性绕过剥离，并在打开档案时执行，<sup>[11](https://issues.chromium.org/issues/503865896)</sup> 另一份报告描述了不完整的脚本剥离，在保存的文件中同时留下了隐私数据和恶意脚本，该脚本甚至能通过 [WebSocket](https://www.edgepedia.org/zh/websocket) 窃取数据，尽管在 MHTML 上下文中普通的 fetch 调用是被阻止的。<sup>[12](https://issues.chromium.org/issues/499194407)</sup>

较旧的微软实现有其自身的缺陷。MS03-014 修复了一个漏洞，其中 Outlook Express MHTML URL 处理器可以将任何文本文件渲染为 HTML，可能以本地计算机区域权限执行脚本；该补丁将处理器限制为仅处理 .mht 和 .mhtml 文件。<sup>[7](https://learn.microsoft.com/en-us/security-updates/securitybulletins/2003/ms03-014)</sup> 一份相关的 CERT 漏洞公告描述了 Outlook Express MHTML 协议处理器将来自某个域的内容视为位于本地计算机区域，违反了跨域安全模型。<sup>[13](https://www.kb.cert.org/vuls/id/323070)</sup>

## 与其他归档格式的比较

MHTML 是将网页保存为单个文件的几种方式之一。Safari 的 .webarchive 将页面存储在 Apple 二进制属性列表中，仅在 Safari 中可原生重新打开，而 MHTML 可在 Chrome 和 Edge 中原生重新打开；两者都不能取代 WARC——网页归档和爬虫所使用的格式。<sup>[14](https://formats.jarhalab.com/comparisons/webarchive-vs-mhtml)</sup> Mozilla Archive Format 附加组件的 MAFF 容器在单文件归档方面与 MHTML 相当，尽管两种格式在其他方面有所不同。<sup>[15](https://www.amadzone.org/mozilla-archive-format/maff-specification.html)</sup> SingleFile 风格的工具将资源作为 data URI 嵌入纯 HTML 文件，而 Chrome 的“网页，完整”选项保存的是一个 HTML 文件加一个资源文件夹，而非单个文件。<sup>[3](https://formats.jarhalab.com/formats/mhtml)</sup>

MHTML 作为保存格式也有局限。对于大规模采集，网页归档使用 WARC 代替。<sup>[16](https://arxiv.org/abs/2003.14046)</sup>

## References

1. [Palme, J., Hopmann, A., Shelness, N. (1999). MIME Encapsulation of Aggregate Documents, such as HTML (MHTML). RFC 2557, IETF.](https://datatracker.ietf.org/doc/html/rfc2557)
2. [MHTML File - What It Is, How to Open & Convert It, File-Extension.info](https://www.file-extension.info/format/mhtml)
3. [MHTML .mhtml Format, File Formats (Jarhalab)](https://formats.jarhalab.com/formats/mhtml)
4. [MIME Encapsulation of Aggregate HTML Documents (mhtml) Working Group, IETF Datatracker](https://datatracker.ietf.org/wg/mhtml/about/)
5. [Palme, J., Hopmann, A. (1997). MIME E-mail Encapsulation of Aggregate Documents, such as HTML (MHTML). RFC 2110, IETF.](https://datatracker.ietf.org/doc/html/rfc2110)
6. [MHT / MHTML file format, Archive Explorer](https://archiveexplorer.com/formats/mht)
7. [Microsoft Security Bulletin MS03-014, Microsoft Learn](https://learn.microsoft.com/en-us/security-updates/securitybulletins/2003/ms03-014)
8. [Issue 10069014: Save Page As MHTML, Chromium Code Review](https://codereview.chromium.org/10069014)
9. [InternetExplorerIntegrationLocalMhtFileAllowed policy, Microsoft Learn](https://learn.microsoft.com/en-us/deployedge/microsoft-edge-browser-policies/internetexplorerintegrationlocalmhtfileallowed)
10. [Bug 86540: MHTML files should be loadable from all schemes considered local, WebKit](https://bugs.webkit.org/show_bug.cgi?id=86540)
11. [Issue 503865896: Potential Information Leak via Case-Sensitive Attribute Filter Bypass in FrameSerializer (MHTML), Chromium](https://issues.chromium.org/issues/503865896)
12. [Issue 499194407: Information Leak via Incomplete Script Stripping in FrameSerializer (MHTML), Chromium](https://issues.chromium.org/issues/499194407)
13. [VU#323070: Outlook Express MHTML protocol handler does not properly validate source of alternate content, CERT/CC](https://www.kb.cert.org/vuls/id/323070)
14. [Safari WebArchive vs MHTML: Which to Use?, File Formats (Jarhalab)](https://formats.jarhalab.com/comparisons/webarchive-vs-mhtml)
15. [MAFF Specification, Mozilla Archive Format Add-on](https://www.amadzone.org/mozilla-archive-format/maff-specification.html)
16. [The Case For Alternative Web Archival Formats To Expedite The Data-To-Insight Cycle, arXiv](https://arxiv.org/abs/2003.14046)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › HTTP and web communication protocols

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/mhtml

English original: https://www.edgepedia.org/mhtml
