MAIL-PARSER · CVE-2026-129301 · Package
FIX → 4.6.3
mail-parser is a Python library for parsing emails. A crafted MIME attachment (bad filename or undecodable base64) makes write_attachments() stop early, so later attachments are not written and availability suffers.
first public Aug 19, 2026 · 2 sources
Check it with your coding agent
It reads this page and tells you if your code or app is affected.
Applications using mail-parser from 4.6.0 up to 4.6.3 that call write_attachments() on untrusted email. A scanner or sandbox that reads only the extraction directory can miss a payload after the crafted part. Teams that do not extract attachments from untrusted mail can skip it.
Not affected if no-attachment-extraction, no-untrusted-email
Who cares email-processing, mail-parser, python
pip show mail-parser or pip freeze | grep -i mail-parser and compare against 4.6.3write_attachments() calls in your code that parse untrusted emailUpgrade to 4.6.3
4.6.3write_attachments() called _safe_attachment_filename() and write_sample() inside its loop
with no guard, so a single crafted attachment raised out of the whole save. Every attachment
after the malicious one was silently never written, with no error surfaced to a caller that
catches only MailParserError.
That is an evasion primitive as much as an availability bug: a sender puts one poisoned part first and the real payload second, and the payload never reaches the extraction directory that a downstream scanner or sandbox reads — while it still reaches the recipient's mail client intact. The tool's output diverges from the bytes actually in the message, which is the same failure mode as the filename-sanitizing bypass in GHSA-fr3h-cpq2-9496.
Three shapes were reachable, all from attacker-controlled MIME metadata:
filename*=us-ascii''evil%00.bin decodes to a NUL in the
filename during parsing and raised ValueError out of the name check;NAME_MAX (e.g. 300 characters) raised
from , creating a zero-byte stub on disk;Are you affected?
Ask from here. InfraStack checks the affected versions against your stack and answers in your inbox.
InfraStack checks the affected versions against your stack and answers in Slack, with the evidence and the fix.
InfraStack checks it against your stack and answers on your report, with the evidence and the fix.
OSError: File name too longopen()binascii.Error (a
ValueError subclass) from the decode performed inside the open() block.import tempfile, mailparser
raw = ("Content-Type: multipart/mixed; boundary=b\r\n\r\n"
"--b\r\nContent-Type: application/octet-stream\r\n"
"Content-Disposition: attachment; filename*=us-ascii''evil%00.bin\r\n\r\nxx\r\n"
"--b\r\nContent-Type: application/octet-stream\r\n"
"Content-Disposition: attachment; filename=good.bin\r\n\r\nyy\r\n"
"--b--\r\n")
mp = mailparser.parse_from_string(raw) # parse itself is fine; safe_filename is None
mp.write_attachments(tempfile.mkdtemp())
# 4.6.0 - 4.6.2 -> ValueError, and good.bin is never written
# 4.6.3 -> logs "Skipped attachment with invalid filename: 'evil\x00.bin'";
# good.bin is written
parse() itself was never affected — it catches the ValueError — so only the write path was
unguarded. The reject-paths that made this reachable were introduced with the filename
sanitizing in 4.6.0 (PR #165).
Fixed in 4.6.3. write_attachments() now logs and skips a single unusable attachment
instead of aborting the batch:
open();open(), so a failure leaves no zero-byte stub, and it now
repairs padding and alphabet errors the way mail clients do (matching MIME::Base64 on 2008
cases) — rejecting them let a sender append one character to make an attachment vanish from
the extraction directory while it still reached the recipient;MailParserPathError is deliberately not caught by the per-attachment handler: a
containment failure is not a per-attachment problem, and path-containment checks now raise
MailParserPathError instead of ValueError so the broader catch cannot swallow them.Deduplication was hardened in the same change: it reserves room for its own suffix marker
(write_sample() sanitizes again, and the clamp there used to cut the marker back off,
collapsing distinct attachments onto one file), resumes from the last used suffix per stem
instead of rescanning from 1 (quadratic before — 16000 same-named attachments took 14 s, now
milliseconds), and folds case, because APFS, exFAT and SMB collapse Invoice.pdf and
invoice.pdf.
Upgrade to 4.6.3. If you cannot upgrade, do not call write_attachments() on untrusted mail;
iterate parser.attachments yourself and write each attachment inside its own
try/except Exception, skipping the ones whose safe_filename is None.
This page as .md · .json · CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L
NVD data is provided by NIST and is public domain · GitHub Advisory Database, CC-BY 4.0. Posts quoted belong to their authors.