---
id: "CVE-2026-129299"
page: "https://infrastack.ai/live/CVE-2026-129299"
kind: "vulnerability"
aliases: ["CVE-2026-129299", "GHSA-24mq-4vc6-2prf"]
title: "mail-parser: Uncaught exceptions and silent header loss in mail-parser on attacker-controlled input"
severity: "medium"
cvss: 6.5
epss: null
exploited: false
status: "open"
category: "package"
products: [{"name": "mail-parser", "fixed": ["4.6.2"], "affected": "<= 4.6.1", "ecosystem": "pypi"}]
ecosystems: ["pypi"]
tags: ["cwe-248", "cwe-436", "email-processing", "mail-parser", "package", "python"]
not_affected_if: ["no-untrusted-email-input", "version-4.6.2-or-later"]
published_at: "2026-11-16T18:17:30+00:00"
first_seen_at: "2026-11-16T18:38:03+00:00"
updated_at: "2026-11-16T22:17:23+00:00"
sources: [{"source": "nvd", "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-129299", "first_seen_at": "2026-11-16T18:38:03+00:00"}, {"source": "ghsa", "url": "https://github.com/advisories/GHSA-24mq-4vc6-2prf", "first_seen_at": "2026-11-16T22:17:23+00:00"}]
exploit_sources: []
---

# mail-parser: Uncaught exceptions and silent header loss in mail-parser on attacker-controlled input

Link for people: https://infrastack.ai/live/CVE-2026-129299 (this .md is for agents)

mail-parser is a Python library for parsing email messages. Crafted headers can raise exceptions, silently drop content, or make body and attachment fields come back empty, which can abort processing or hide indicators from downstream scanners.

_Summary, check and fix written by a model from the sources; labelled as such._

## Affected

- pypi:mail-parser affected <= 4.6.1 fixed 4.6.2

## How to check

- `pip show mail-parser` or check the installed version in requirements.txt or the lockfile
- Confirm whether the affected version is below `4.6.2`

## Fix

- Upgrade mail-parser to `4.6.2` or later

## Timeline

- 2026-11-16T18:38:03+00:00 nvd https://nvd.nist.gov/vuln/detail/CVE-2026-129299
- 2026-11-16T22:17:23+00:00 ghsa https://github.com/advisories/GHSA-24mq-4vc6-2prf

## Documents

- [advisory] Vendor advisory: github.com https://github.com/SpamScope/mail-parser/security/advisories/GHSA-24mq-4vc6-2prf
- [advisory] Maintainer's advisory: api.github.com https://api.github.com/repos/SpamScope/mail-parser/security-advisories/GHSA-24mq-4vc6-2prf
- [fix] Patch: github.com https://github.com/SpamScope/mail-parser/commit/ce3cf3559db1ff806bda598b378de9f8c2a5be96
- [fix] Release notes: github.com https://github.com/SpamScope/mail-parser/releases/tag/4.6.2
- [fix] Patch: github.com https://github.com/SpamScope/mail-parser/pull/167

## From the sources

### Impact

Two effects, sharing the root cause of Advisory 1 — header names chosen by the sender were
resolved through Python attribute lookup and rewritten before lookup.

**Uncaught exceptions.** A crafted message raises an exception that is *outside* the
`MailParser*` hierarchy, so a caller catching only mail-parser exceptions does not catch it
and the worker dies.

*Header named after a method* (CWE-248, reported by @iam-niranjan). Python resolves real
class attributes before `__getattr__`, so a header named after a method put a bound method
object into the parsed mail dict. A 12-byte email is sufficient. Nine colliding names were
confirmed: `Parse`, `Message`, `Write_Attachments`, `From_File`, `From_File_Obj`,
`From_File_Msg`, `From_String`, `From_Bytes`, `Get_Server_Ipaddress`. Also reproducible from
the CLI (`mail-parser -f evil.eml -j`).

```python
import mailparser
mailparser.parse_from_string("Parse: x\r\n\r\n").mail_json
# 4.6.1 -> TypeError: Object of type method is not JSON serializable
# 4.6.2 -> {"parse": "x", "has_defects": false}
```

*Header carrying 8-bit bytes* (CWE-248). For a header containing raw 8-bit bytes, Python's
`compat32` policy returns an `email.header.Header` rather than a `str`, which the `_raw`
accessor passed straight to `json.dumps`. This fires on entirely benign non-ASCII mail via
`parse_from_bytes()`, the normal entry point for mail off the wire.

```python
import mailparser
mailparser.parse_from_bytes(b"Subject: caf\xe9\r\n\r\nbody\r\n").subject_raw
# 4.6.1 -> TypeError: Object of type Header is not JSON serializable
# 4.6.2 -> '["caf�"]'
```

**Silent loss of message content** (CWE-436). A sender can make a header's value vanish from
every output surface, or be replaced by a different header's value, with `has_defects`
remaining `false`. This is an evasion primitive: the tool's output diverges from the bytes
actually in the message, and a pipeline scanning parsed output for indicators sees nothing
and no failure signal.

Header names were normalised before lookup — underscores folded to dashes, and `_json` /
`_raw` suffixes interpreted — so a header genuinely named `Subject_json` was reported with
the value of `Subject` and its own value discarded, and any header whose name contains an
underscore resolved to nothing.

```python
import mailparser

raw = ("From: Real Sender <real@good.example>\r\n"
       "Subject: innocuous\r\n"
       "Subject_json: MALWARE-C2 http://evil.example/payload.exe\r\n"
       "X_Spam_Flag: YES\r\n\r\nbody\r\n")
mail = mailparser.parse_from_string(raw)
print(mail.mail["subject_json"])       # 4.6.1 -> '"innocuous"'   4.6.2 -> the real value
print(mail.headers["X_Spam_Flag"])     # 4.6.1 -> ''              4.6.2 -> 'YES'
print("MALWARE-C2" in mail.mail_json)  # 4.6.1 -> False           4.6.2 -> True
print(mail.has_defects)                # both  -> False
```

A related case: `email.message.Message.__len__` returns the header count, so a message with
**no headers** is falsy. `parse()` returned before initialising state, and the unset
attributes were then absorbed by `__getattr__` and answered as absent headers. Every
property returned `''` — including `mail` and `attachments`, which are documented to return
a `dict` and a `list` — with no error and no defect flag.

```python
import mailparser
mail = mailparser.parse_from_string("Click http://evil.example/pay.exe now\r\n")
print(repr(mail.body))         # 4.6.1 -> ''    4.6.2 -> the text
print(repr(mail.attachments))  # 4.6.1 -> ''    4.6.2 -> []
print(mail.has_defects)        # 4.6.1 -> ''    4.6.2 -> True
```

### Patches

Fixed in **4.6.2**. Upgrade with `pip install --upgrade mail-parser`.

Header names taken from a message are now looked up literally — no attribute access, no
case or separator folding, no suffix interpretation — so no header name can collide with a
method or property, and no value can be substituted or dropped. 8-bit values are coerced to
`str` before serialisation. Parser state is initialised before the message check, which now
tests `is None`, and attribute names beginning with `_` raise `AttributeError` instead of
being answered as headers.

**Behaviour changes.** Header names now appear in `mail` and `headers` exactly as sent, so a
header named `X_Spam_Flag` keeps that name and its own value. `X_raw` always returns a JSON
array — an absent header yields `[]` where 4.6.1 returned `null`.

### Workarounds

None for the data loss. For the uncaught exceptions, callers who cannot upgrade should wrap
`mail_json`, `mail_partial_json`, `headers_json` and any `X_raw` access in a bare
`except Exception` rather than catching only `MailParserError` subclasses.

---

_Free to read, with fair use of about 60 pages a minute. For higher limits or API access: sales@infrastack.ai_
