CVE-2026-129301
MailParser batch write aborts on malicious MIME parts, causing data loss.
- CVSS 6.5
- CWE-248
- 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 4.6.0 until 4.6.3, write_attachments() calls _safe_attachment_filename() and write_sample() without isolating failures for individual attacker-controlled MIME parts. An RFC 2231 filename containing a NUL, a basename exceeding NAME_MAX, or an undecodable base64 payload can raise ValueError, OSError, or binascii.Error and abort the entire save loop. Later attachments remain unwritten; when a caller catches only MailParserError, the failure is not surfaced through the expected library-exception path. If a downstream scanner or sandbox reads only the extraction directory, a payload after the crafted part can be missed even though it remains in the delivered message, and the aborted batch also causes availability loss. This issue is fixed in version 4.6.3.
- CWE
- CWE-248
- CVSS base score
- 6.5
- Published
- 2026-11-16
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Affected component
- mail-parser
- Fixed by upgrading
- Yes
Solution
Upgrade mail-parser to version 4.6.3 or later.
Vulnerable code sample
import os, binascii
from mailparser import MailParser
def extract_attachments(raw_email: bytes, out_dir: str) -> None:
"""
Save all attachments from the given raw email into out_dir.
"""
parser = MailParser.from_bytes(raw_email)
# VULNERABLE: aborts on malformed attachment filename or payload
for part in parser.attachments:
filename = parser._safe_attachment_filename(part)
data = part.get_payload(decode=True)
# This call can raise ValueError, OSError, or binascii.Error
with open(os.path.join(out_dir, filename), "wb") as fh:
fh.write(data)Patched code sample
import os, binascii
from mailparser import MailParser
def extract_attachments(raw_email: bytes, out_dir: str) -> None:
"""
Save all attachments from the given raw email into out_dir.
"""
parser = MailParser.from_bytes(raw_email)
# FIX: isolate failures for each attachment
for part in parser.attachments:
try:
filename = parser._safe_attachment_filename(part)
data = part.get_payload(decode=True)
with open(os.path.join(out_dir, filename), "wb") as fh:
fh.write(data)
except (ValueError, OSError, binascii.Error):
continuePublished 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.
- fix: stop one bad attachment from costing the whole batch (SpamScope/mail-parser)
src/mailparser/exceptions.py,src/mailparser/utils.py,src/mailparser/utils.py · print_attachments,src/mailparser/utils.py · write_attachments,src/mailparser/utils.py · write_sample,src/mailparser/utils.py · _deduplicate_filename,src/mailparser/utils.py · _safe_attachment_filename - fix: attachment integrity, batch availability, and date overflow on hostile mail (#171) (SpamScope/mail-parser)
src/mailparser/core.py,src/mailparser/core.py · MailParser.message_as_string,src/mailparser/core.py · MailParser.parse,src/mailparser/utils.py,src/mailparser/utils.py · ported_string,src/mailparser/utils.py · receiveds_format
Cite this entry
@misc{vaitp:cve2026129301,
title = {{MailParser batch write aborts on malicious MIME parts, causing data loss.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-129301},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-129301/}}
}
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 ::
