CVE-2026-129295
Regex backtracking DoS via crafted email headers in mail‑parser 4.2.0‑4.6.1.
- CVSS 7.5
- CWE-1333
- Input Validation and Sanitization
- Remote
mail-parser is a tool that parses emails by enhancing the Python standard library and extracting message details into a comprehensive object. From 4.2.0 until 4.6.1, attacker-controlled email headers can cause polynomial regular-expression backtracking during ordinary parse_from_string(), parse_from_bytes(), or parse_from_file() calls. In src/mailparser/utils.py, get_addresses() invokes the _ADDR_FALLBACK_RE fallback when strict address parsing yields no usable address, and overlapping quantifiers rescan padded address headers quadratically or cubically. In src/mailparser/const.py, parse_received() applies _CLAUSE_SPLITTER to uncollapsed whitespace in a Received header, causing quadratic backtracking when a whitespace run is not followed by a clause keyword. A small, well-formed message can keep mail gateway, ticketing, quarantine, or archival parsing workers busy for extended periods. This issue is fixed in version 4.6.1.
- CWE
- CWE-1333
- CVSS base score
- 7.5
- Published
- 2026-11-16
- OWASP
- A04 Insecure Design
- Orthogonal defect classification
- Timing/Serialization
- Code defect classification
- Timing Issues
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Affected component
- mail-parser
- Fixed by upgrading
- Yes
Solution
Upgrade mail-parser to version 4.6.1 (or later).
Vulnerable code sample
import re
from mailparser import utils, const
def parse_email(raw):
# extract addresses using the vulnerable fallback regex
# VULNERABLE: overlapping quantifiers cause catastrophic backtracking
addr_pattern = re.compile(r'(?:(\S+)\s+)+') # matches one or more non‑space tokens followed by spaces, repeated
addresses = []
for header, value in utils.get_headers(raw):
m = const._STRICT_ADDR_RE.search(value)
if not m:
m = addr_pattern.search(value) # fallback parsing
if m:
addresses.append(m.group(1))
return addresses
def parse_received(header):
# VULNERABLE: quadratic backtracking on long whitespace runs
parts = const._CLAUSE_SPLITTER.split(header) # splitter uses r'\s+(?=\s*)'
return [p.strip() for p in parts if p]Patched code sample
import re
from mailparser import utils, const
def parse_email(raw):
# FIX: replace overlapping quantifiers with a linear pattern
addr_pattern = re.compile(r'(\S+)(?:\s+(\S+))*') # captures first address without catastrophic backtracking
addresses = []
for header, value in utils.get_headers(raw):
m = const._STRICT_ADDR_RE.search(value)
if not m:
m = addr_pattern.search(value) # fallback parsing
if m:
addresses.append(m.group(1))
return addresses
def parse_received(header):
# FIX: collapse whitespace before splitting to avoid backtracking
collapsed = re.sub(r'\s+', ' ', header)
parts = const._CLAUSE_SPLITTER.split(collapsed)
return [p.strip() for p in parts if p]Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- feat: improve address parsing performance and robustness against ReDoS (SpamScope/mail-parser)
src/mailparser/utils.py,src/mailparser/utils.py · get_addresses - Security hardening: ReDoS, recursion DoS, and Outlook-path robustness (#166) (SpamScope/mail-parser)
src/mailparser/const.py,src/mailparser/core.py,src/mailparser/core.py · MailParser.from_bytes,src/mailparser/core.py · MailParser.from_file,src/mailparser/core.py · MailParser.from_string,src/mailparser/exceptions.py,src/mailparser/utils.py,src/mailparser/utils.py · msgconvert,src/mailparser/utils.py · parse_received - feat: enhance security by adding regex normalization and safe file removal (SpamScope/mail-parser)
src/mailparser/core.py,src/mailparser/core.py · MailParser.from_file,src/mailparser/utils.py
Cite this entry
@misc{vaitp:cve2026129295,
title = {{Regex backtracking DoS via crafted email headers in mail‑parser 4.2.0‑4.6.1.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-129295},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-129295/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
