MEDIUM · CVSS 3.1 6.5 EPSS 0.5% · 32th percentile CWE-248CWE-436

CVE-2026-129301: mail-parser: One hostile attachment aborts `write_attachments()` and silently drops the rest of the batch

Published 2026-11-16 · Updated 2026-11-16 · Also known as GHSA-8cgq-x343-p74c

Summary

The mail-parser package fails to catch exceptions raised during attachment writes in versions 4.6.0 through 4.6.2, causing a single hostile attachment to silently drop the rest of the batch. Maintainers using these versions should upgrade immediately to secure their email processing pipelines.

Who is affected

Applications utilizing mail-parser versions 4.6.0 to 4.6.2 to extract email attachments are vulnerable when processing messages containing attacker-controlled MIME metadata. Specially crafted attachments featuring NUL bytes in filenames, overlong basenames, or undecodable payloads will raise unhandled exceptions during write_attachments(), causing all subsequent attachments in the batch to be silently omitted from the extraction directory while remaining intact for the recipient.

Exploitability

The vulnerability carries a CVSS base score of 6.5 with a vector of CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L, indicating that exploitation requires network access with low complexity and no privileges or user interaction. The EPSS score is 0.003 and CISA KEV status is no, meaning active exploitation is not currently documented in known catalogs.

Remediation

How to check your project

Automated analysis of the published advisory data, generated 2026-11-18. Not human-reviewed; verify against the official advisory. How this works.

Affected packages

EcosystemPackageAffected versionsFixed inUpgrade
PyPI mail-parser >= 4.6.0, < 4.6.3 4.6.3 python -m pip install 'mail-parser>=4.6.3'

CVSS 3.1 vector

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L

Attack vectorNetwork
Attack complexityLow
Privileges requiredNone
User interactionNone
ScopeUnchanged
ConfidentialityNone
IntegrityLow
AvailabilityLow

FAQ

What causes the attachments to be dropped?

A single crafted attachment using NUL bytes, overlong basenames, or invalid base64 encoding triggers an unhandled exception inside the write_attachments() loop, aborting the process and preventing the remaining attachments from being written.

Is the mail parsing function itself affected?

No, the parse() function is unaffected because it catches the ValueError, meaning the issue is strictly contained to the attachment writing path introduced in version 4.6.0.

How does version 4.6.3 resolve the issue?

Version 4.6.3 wraps individual attachment processing in a way that catches, logs, and skips unusable attachments rather than aborting the entire batch, while also truncating overlong names and safely reordering base64 decoding.

Original advisory description
### Impact `write_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](https://github.com/SpamScope/mail-parser/security/advisories/GHSA-fr3h-cpq2-9496). Three shapes were reachable, all from attacker-controlled MIME metadata: - **NUL smuggled through RFC 2231** - `filename*=us-ascii''evil%00.bin` decodes to a NUL in the filename during parsing and raised `ValueError` out of the name check; - **overlong basename** - a filename longer than `NAME_MAX` (e.g. 300 characters) raised `OSError: File name too long` from `open()`, *after* creating a zero-byte stub on disk; - **undecodable payload** - a body that is not valid base64 raised `binascii.Error` (a `ValueError` subclass) from the decode performed inside the `open()` block. ```python 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). ### Patches Fixed in **4.6.3**. `write_attachments()` now logs and skips a single unusable attachment instead of aborting the batch: - an invalid filename is caught and skipped; - overlong basenames are truncated to 240 UTF-8 bytes, preserving the extension, rather than reaching `open()`; - the base64 decode moved *before* `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`. ### Workarounds 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`.

References

Source records: GHSA-8cgq-x343-p74c (OSV.dev) · EPSS by FIRST, 2026-11-26.