Vulnerabilities in pkg:pypi/mail-parser

PACKAGE
Advisory Identifier: GHSA-8cgq-x343-p74c
Advisory Summary

CVE-2026-129301 is a MODERATE (CVSS 6.5) one hostile attachment aborts `write_attachments()` vulnerability (CWE-436: Interpretation Conflict) affecting mail-parser libraries in the PyPI ecosystem. The issue involves one hostile attachment aborts `write_attachments()` and silently drops the rest of the batch. Remediation is available by upgrading affected packages to version 4.6.3.

6 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:pypi/mail-parser

6 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:pypi/mail-parser. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-8cgq-x343-p74c CVE-2026-129301 MODERATE mail-parser: One hostile attachment aborts `write_attachments()` and silently drops the rest of the batch
GHSA-xhrq-2mqv-q8wx CVE-2026-129300 MODERATE mail-parser: Uncaught `OverflowError` / `OSError` on an out-of-range `Received` date
GHSA-24mq-4vc6-2prf CVE-2026-129299 MODERATE mail-parser: Uncaught exceptions and silent header loss in mail-parser on attacker-controlled input
GHSA-72px-j8gh-p79x CVE-2026-129297 HIGH mail-parser: Sender IP address spoofing in get_server_ipaddress()
GHSA-r7w7-vpq8-c5vv CVE-2026-129295 HIGH mail-parser is vulnerable to polynomial ReDoS in email header parsing
GHSA-fr3h-cpq2-9496 CVE-2026-129296 MODERATE mail-parser: Path Traversal vulnerability in attachment extraction

CVE-2026-129301 at a Glance

CVE Identifier CVE-2026-129301
GHSA Identifier GHSA-8cgq-x343-p74c
Severity MODERATE
CVSS v3.1 Base Score 6.5
CWE Classification CWE-436: Interpretation Conflict
Affected Product mail-parser
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 6.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity Low (I:L)
Availability Low (A:L)

How to Fix CVE-2026-129301

To remediate this vulnerability, upgrade all affected mail-parser dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

mail-parser fixed: 4.6.3
pip install mail-parser>=4.6.3
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show mail-parser

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2026-129301, inspect your installed packages using pip:

pip show mail-parser

Analyze the terminal output to locate any version of mail-parser in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.6.3), your application is affected.

Note: The pip show mail-parser command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-436: Interpretation Conflict, where product a handles inputs or steps differently than product b, which causes a to perform incorrect actions based on its perception of b's state. In mail-parser, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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`.

CVE-2026-129301 Affected mail-parser Versions

1 component(s)
Fixed Versions:
4.6.3
Product / Package Ecosystem Affected Versions Fixed Version
mail-parser
PyPI
≥ 4.6.0
< 4.6.3
4.6.3

References

Frequently Asked Questions

What is CVE-2026-129301?
CVE-2026-129301 is a security vulnerability in mail-parser involving One hostile attachment aborts `write_attachments()` and silently drops the rest of the batch under CWE-436: Interpretation Conflict.
Which mail-parser versions are affected?
Affected versions include releases prior to 4.6.3 across affected packages: mail-parser.
What version fixes CVE-2026-129301?
Upgrading to 4.6.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is mail-parser affected?
Yes, mail-parser is affected in releases prior to 4.6.3. Upgrade your dependency to 4.6.3 or later.
What is the CVSS score of CVE-2026-129301?
CVE-2026-129301 has a CVSS v3.1 base score of 6.5 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L.
What CWE is associated with CVE-2026-129301?
CVE-2026-129301 is classified under CWE-436: Interpretation Conflict (Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.).
How can I check PyPI dependencies for CVE-2026-129301?
Run the dependency tree command: 'pip show mail-parser'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-8cgq-x343-p74c",
  "modified" : "2026-11-16T22:22:13Z",
  "published" : "2026-11-16T22:22:13Z",
  "aliases" : [ "CVE-2026-129301" ],
  "summary" : "mail-parser: One hostile attachment aborts `write_attachments()` and silently drops the rest of the batch",
  "details" : "### Impact\n\n`write_attachments()` called `_safe_attachment_filename()` and `write_sample()` inside its loop\nwith no guard, so a single crafted attachment raised out of the whole save. Every attachment\n**after** the malicious one was silently never written, with no error surfaced to a caller that\ncatches only `MailParserError`.\n\nThat is an evasion primitive as much as an availability bug: a sender puts one poisoned part\nfirst and the real payload second, and the payload never reaches the extraction directory that\na downstream scanner or sandbox reads — while it still reaches the recipient's mail client\nintact. The tool's output diverges from the bytes actually in the message, which is the same\nfailure mode as the filename-sanitizing bypass in\n[GHSA-fr3h-cpq2-9496](https://github.com/SpamScope/mail-parser/security/advisories/GHSA-fr3h-cpq2-9496).\n\nThree shapes were reachable, all from attacker-controlled MIME metadata:\n\n- **NUL smuggled through RFC 2231** — `filename*=us-ascii''evil%00.bin` decodes to a NUL in the\n  filename during parsing and raised `ValueError` out of the name check;\n- **overlong basename** — a filename longer than `NAME_MAX` (e.g. 300 characters) raised\n  `OSError: File name too long` from `open()`, *after* creating a zero-byte stub on disk;\n- **undecodable payload** — a body that is not valid base64 raised `binascii.Error` (a\n  `ValueError` subclass) from the decode performed inside the `open()` block.\n\n```python\nimport tempfile, mailparser\n\nraw = (\"Content-Type: multipart/mixed; boundary=b\\r\\n\\r\\n\"\n       \"--b\\r\\nContent-Type: application/octet-stream\\r\\n\"\n       \"Content-Disposition: attachment; filename*=us-ascii''evil%00.bin\\r\\n\\r\\nxx\\r\\n\"\n       \"--b\\r\\nContent-Type: application/octet-stream\\r\\n\"\n       \"Content-Disposition: attachment; filename=good.bin\\r\\n\\r\\nyy\\r\\n\"\n       \"--b--\\r\\n\")\n\nmp = mailparser.parse_from_string(raw)     # parse itself is fine; safe_filename is None\nmp.write_attachments(tempfile.mkdtemp())\n# 4.6.0 - 4.6.2 -> ValueError, and good.bin is never written\n# 4.6.3         -> logs \"Skipped attachment with invalid filename: 'evil\\x00.bin'\";\n#                  good.bin is written\n```\n\n`parse()` itself was never affected — it catches the `ValueError` — so only the write path was\nunguarded. The reject-paths that made this reachable were introduced with the filename\nsanitizing in 4.6.0 (PR #165).\n\n### Patches\n\nFixed in **4.6.3**. `write_attachments()` now logs and skips a single unusable attachment\ninstead of aborting the batch:\n\n- an invalid filename is caught and skipped;\n- overlong basenames are truncated to 240 UTF-8 bytes, preserving the extension, rather than\n  reaching `open()`;\n- the base64 decode moved *before* `open()`, so a failure leaves no zero-byte stub, and it now\n  repairs padding and alphabet errors the way mail clients do (matching `MIME::Base64` on 2008\n  cases) — rejecting them let a sender append one character to make an attachment vanish from\n  the extraction directory while it still reached the recipient;\n- `MailParserPathError` is deliberately **not** caught by the per-attachment handler: a\n  containment failure is not a per-attachment problem, and path-containment checks now raise\n  `MailParserPathError` instead of `ValueError` so the broader catch cannot swallow them.\n\nDeduplication was hardened in the same change: it reserves room for its own suffix marker\n(`write_sample()` sanitizes again, and the clamp there used to cut the marker back off,\ncollapsing distinct attachments onto one file), resumes from the last used suffix per stem\ninstead of rescanning from 1 (quadratic before — 16000 same-named attachments took 14 s, now\nmilliseconds), and folds case, because APFS, exFAT and SMB collapse `Invoice.pdf` and\n`invoice.pdf`.\n\n### Workarounds\n\nUpgrade to 4.6.3. If you cannot upgrade, do not call `write_attachments()` on untrusted mail;\niterate `parser.attachments` yourself and write each attachment inside its own\n`try`/`except Exception`, skipping the ones whose `safe_filename` is `None`.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "mail-parser"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.6.0"
      }, {
        "fixed" : "4.6.3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/SpamScope/mail-parser/security/advisories/GHSA-8cgq-x343-p74c"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-129301"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/SpamScope/mail-parser/pull/171"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/SpamScope/mail-parser/commit/11b894a0b8b3f11055a99caff118206138d1daba"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/SpamScope/mail-parser/commit/e1d9fe6778045d6e2c44406bc8822e3464c1097f"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/SpamScope/mail-parser"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/SpamScope/mail-parser/releases/tag/4.6.3"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-248", "CWE-436" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-11-16T22:22:13Z",
    "nvd_published_at" : "2026-11-16T18:17:31Z"
  }
}