mail-parser: Uncaught `OverflowError` / `OSError` on an out-of-range `Received` dateGHSA-xhrq-2mqv-q8wx
MEDIUMFix: SpamScope/mail-parser#171GHSA-xhrq-2mqv-q8wx is a medium-severity (CVSS 5.3) CWE-248 vulnerability in mail-parser. A fix is available for mail-parser — see the affected versions and patch details below.
Exploitation Status
No confirmed exploitation observed yet
- CISA assesses this as automatable — exploitation doesn’t require manual, per-target effort, which raises the odds of mass scanning and opportunistic attacks.
- CISA’s own triage has not observed active exploitation or public proof-of-concept code for this CVE as of its last assessment.
Exploitation and automatability from CISA’s SSVC triage for GHSA-xhrq-2mqv-q8wx.
Real-World Exposure
mail-parserReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects PyPI packages — download data is not available via public APIs for these ecosystems.
Description
Impact
A Received header whose trailing date carries an out-of-range year, or a timezone offset
large enough to push the timestamp past the int64 epoch range, raises an exception that is
outside the MailParser* hierarchy. A caller that catches only mail-parser exceptions
does not catch it, and the parse of the entire message is aborted — the same class of issue
as GHSA-24mq-4vc6-2prf,
which this survives (it is not a duplicate; 24mq is fixed in 4.6.2 and this reproduces on 4.6.2).
All entry points are affected: parse_from_string(), parse_from_bytes(), parse_from_file(),
parse_from_file_obj() and the mail-parser CLI. The header is fully attacker-controlled and
a single line is enough, so any pipeline that parses untrusted mail can be made to lose the
message — and, if one worker handles a queue, to drop the batch.
import mailparser
raw = ("Received: from x ([1.2.3.4]) by mx.victim.com; "
"Tue, 7 Mar 292277026596 14:29:24 +0000\r\n\r\nbody\r\n")
mailparser.parse_from_string(raw).mail_json
# <= 4.6.2 -> OverflowError: signed integer is greater than maximum
# 4.6.3 -> parses; the unusable hop date is reported as "date_utc": null
Root cause. receiveds_format() in src/mailparser/utils.py guarded the date conversion
with except (TypeError, ValueError), but convert_mail_date() → email.utils.mktime_tz() →
calendar.timegm() raises OverflowError for years whose epoch seconds overflow int64, and
datetime.fromtimestamp() reports EOVERFLOW as OSError for a sufficiently large timezone
offset. The date and timezone properties already wrapped the same conversion in
except Exception; only the Received path was left open.
Affected range. Introduced by the date-handling change in ca2aa6a, first released in
3.7.0. Reproduced on PyPI 3.7.0, 3.8.0, 3.9.3, 4.0.0, 4.5.0, 4.6.0, 4.6.2 and on master
before the fix (Python 3.14). 3.6.0 is not affected.
Patches
Fixed in 4.6.3. receiveds_format() now also catches OverflowError and OSError and
records date_utc = None for that hop, so the rest of the message still parses:
try:
j["date_utc"], _ = convert_mail_date(i["date"])
except (TypeError, ValueError, OverflowError, OSError):
j["date_utc"] = None
A sweep of year magnitudes from 10^7 to 10^12 shows only ValueError, OverflowError and
OSError are reachable on this path.
Workarounds
Upgrade to 4.6.3. If you cannot upgrade, wrap every parse_from_* call in a bare
except Exception rather than except MailParserError, and treat the message as unparsed.
References
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 🐍PyPI | mail-parser | ≥ 3.7.0&&< 4.6.3 | 4.6.3pip install --upgrade 'mail-parser==4.6.3' |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for mail-parser, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update mail-parser to 4.6.3 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-xhrq-2mqv-q8wx is resolved across your whole dependency graph.
Workarounds
Stop feeding it untrusted input: reject or quarantine files and payloads from unverified sources until you can upgrade, restrict accepted formats to the ones you actually need, and run the parsing or decoding step in a least-privileged sandbox or short-lived worker so a crash or corrupted read cannot reach the rest of the process.
Frequently Asked Questions
Is GHSA-xhrq-2mqv-q8wx in your dependencies?
Find it across PyPI, including transitive dependencies.