CVE-2026-129296
Path traversal in mail-parser write_attachments enables arbitrary overwrite
- CVSS 6.5
- CWE-22
- Input Validation and Sanitization
- Remote
mail-parser is a tool that parses emails by enhancing the Python standard library and extracting message details into a comprehensive object. From 3.8.0 until 4.6.0, the write_attachments() and write_sample() APIs use attacker-controlled attachment filenames without sufficient sanitization and path containment validation. Directory traversal sequences and absolute filesystem paths can cause an attachment to be written outside the intended output directory. An attacker can overwrite files accessible to the parsing process when an application extracts attachments from a crafted message. This issue is fixed in version 4.6.0.
- CWE
- CWE-22
- CVSS base score
- 6.5
- Published
- 2026-11-16
- OWASP
- A05 Security Misconfiguration
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Path Traversal
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- mail-parser
- Fixed by upgrading
- Yes
Solution
Upgrade mail-parser to version 4.6.0 (or later).
Vulnerable code sample
import os
from mailparser import MailParser
def extract_attachments(email_path: str, out_dir: str) -> None:
"""Extract all attachments from an email file into out_dir."""
parser = MailParser()
parser.parse_from_file(email_path)
# VULNERABLE: writes attachment using attacker-controlled filename directly
for att in parser.attachments:
target_path = os.path.join(out_dir, att['filename'])
with open(target_path, "wb") as f:
f.write(att['payload'])Patched code sample
import os
from mailparser import MailParser
def extract_attachments(email_path: str, out_dir: str) -> None:
"""Extract all attachments from an email file into out_dir."""
parser = MailParser()
parser.parse_from_file(email_path)
# FIX: sanitize filename and enforce containment within out_dir
for att in parser.attachments:
safe_name = os.path.basename(att['filename'])
target_path = os.path.normpath(os.path.join(out_dir, safe_name))
if not target_path.startswith(os.path.abspath(out_dir) + os.sep):
continue
with open(target_path, "wb") as f:
f.write(att['payload'])Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- feat: enhance attachment handling by sanitizing (#165) (SpamScope/mail-parser)
src/mailparser/core.py,src/mailparser/core.py · MailParser.attachments,src/mailparser/core.py · MailParser.parse,src/mailparser/utils.py,src/mailparser/utils.py · write_attachments,src/mailparser/utils.py · write_sample - feat: enhance attachment handling by sanitizing and deduplicating filenames (SpamScope/mail-parser)
src/mailparser/utils.py,src/mailparser/utils.py · write_attachments
Cite this entry
@misc{vaitp:cve2026129296,
title = {{Path traversal in mail-parser write_attachments enables arbitrary overwrite}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-129296},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-129296/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
