GHSA-R7W7-VPQ8-C5VV

Vulnerability from github – Published: 2026-11-16 22:11 – Updated: 2026-11-16 22:11
VLAI
Summary
mail-parser is vulnerable to polynomial ReDoS in email header parsing
Details

Summary

Two regular expressions used while parsing email headers backtrack polynomially on attacker-controlled input. Parsing a single small, well-formed email can consume minutes to hours of CPU, denying service to any process that parses untrusted mail.

Both are reachable from an ordinary parse_from_string(), parse_from_bytes() or parse_from_file() call — no special API, option, or malformed structure is required by the victim.

Details

1. Address-header fallback regex (src/mailparser/utils.py)

get_addresses() falls back to _ADDR_FALLBACK_RE whenever email.utils.getaddresses(strict=True) yields no usable address. The alternative ([^<,]*?)\s*<([^>]+)> overlaps a lazy quantifier with an adjacent \s* — a space matches both. Driven by finditer, which retries at every offset and rescans the remainder, matching degrades to quadratic on < padding and cubic on whitespace padding.

The fallback engages on the feature's own happy path, e.g. From: alice@example.com <bob@example.com>.

Measured (4.6.0, CPython 3.14, macOS arm64; reproduced identically on Linux and on CPython 3.9, 3.11, 3.12, 3.13):

Padding Parse time
valid address + 750 sp 0.38 s
+ 1500 sp 2.97 s
+ 3000 sp 23.4 s (×7.9/2×)
+ 6 KB sp 185 s
~100 KB sp hours

Fully RFC 5322-compliant folded headers (all lines ≤ 71 octets) trigger the same blowup, so the input passes normal MTA and library checks. ~100 KB of headers is within Postfix's default header_size_limit = 102400.

All six address headers parsed by the library (From, To, Cc, Bcc, Reply-To, Delivered-To) are affected and their cost adds up linearly.

2. Received-header clause splitter (src/mailparser/const.py)

parse_received() splits on _CLAUSE_SPLITTER, (?:^|\s+)(from|by|via|with|id|for|envelope-from)\s+. Under re.split this backtracks quadratically over any whitespace run that is not followed by a clause keyword. The pre-existing normalization collapsed only [\t\n], so literal spaces — including folded-header padding — reached the splitter intact.

Measured: 24 000 spaces in one Received: header → 22 s; ~100 KB → minutes.

Impact

Availability. A handful of small emails keeps every parsing worker of a mail gateway, ticketing system, quarantine UI, or archiving pipeline permanently busy. No confidentiality or integrity impact.

Anyone who parses email they did not author is affected — which is the library's purpose.

Patches

Fixed in 4.6.1.

  • The address fallback is now a linear scan: the header is split into comma-separated items (quote-aware, in Python), then each item is matched against a bounded angle-address <([^<>\s]+)> with the display name derived in Python, falling back to a bare-email match. Each pattern has a single non-nested quantifier over a negated character class → O(n). 2000 padding spaces: 3.5 s → <0.01 s. 256 KB padding: hours → 0.087 s. Output is preserved on every previously supported shape.
  • parse_received() collapses whitespace runs to a single space before splitting, so the splitter's \s+ only ever matches one character → O(n). The date is extracted from the raw header beforehand, so date formatting is unaffected. 24 000 spaces: 22 s → 0.003 s; 200 000 spaces: 0.004 s.

Regression tests assert linear-time behaviour for both paths.

Workarounds

None within the library. Upgrade to 4.6.1.

Users who cannot upgrade immediately should cap total header size before parsing and enforce a wall-clock timeout around each parse.

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "PyPI",
        "name": "mail-parser"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "4.2.0"
            },
            {
              "fixed": "4.6.1"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-129295"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-1333"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-11-16T22:11:08Z",
    "nvd_published_at": "2026-11-16T18:17:30Z",
    "severity": "HIGH"
  },
  "details": "### Summary\n\nTwo regular expressions used while parsing email headers backtrack\npolynomially on attacker-controlled input. Parsing a single small, well-formed\nemail can consume minutes to hours of CPU, denying service to any process that\nparses untrusted mail.\n\nBoth are reachable from an ordinary `parse_from_string()`, `parse_from_bytes()`\nor `parse_from_file()` call \u2014 no special API, option, or malformed structure is\nrequired by the victim.\n\n### Details\n\n**1. Address-header fallback regex (`src/mailparser/utils.py`)**\n\n`get_addresses()` falls back to `_ADDR_FALLBACK_RE` whenever\n`email.utils.getaddresses(strict=True)` yields no usable address. The\nalternative `([^\u003c,]*?)\\s*\u003c([^\u003e]+)\u003e` overlaps a lazy quantifier with an adjacent\n`\\s*` \u2014 a space matches both. Driven by `finditer`, which retries at every\noffset and rescans the remainder, matching degrades to **quadratic** on `\u003c`\npadding and **cubic** on whitespace padding.\n\nThe fallback engages on the feature\u0027s own happy path, e.g.\n`From: alice@example.com \u003cbob@example.com\u003e`.\n\nMeasured (4.6.0, CPython 3.14, macOS arm64; reproduced identically on Linux and\non CPython 3.9, 3.11, 3.12, 3.13):\n\n| Padding                | Parse time         |\n| ---------------------- | ------------------ |\n| valid address + 750 sp | 0.38 s             |\n| + 1500 sp              | 2.97 s             |\n| + 3000 sp              | 23.4 s (\u00d77.9/2\u00d7)   |\n| + 6 KB sp              | 185 s              |\n| ~100 KB sp             | hours              |\n\nFully RFC 5322-compliant folded headers (all lines \u2264 71 octets) trigger the same\nblowup, so the input passes normal MTA and library checks. ~100 KB of headers is\nwithin Postfix\u0027s default `header_size_limit = 102400`.\n\nAll six address headers parsed by the library (`From`, `To`, `Cc`, `Bcc`,\n`Reply-To`, `Delivered-To`) are affected and their cost adds up linearly.\n\n**2. Received-header clause splitter (`src/mailparser/const.py`)**\n\n`parse_received()` splits on `_CLAUSE_SPLITTER`,\n`(?:^|\\s+)(from|by|via|with|id|for|envelope-from)\\s+`. Under `re.split` this\nbacktracks **quadratically** over any whitespace run that is not followed by a\nclause keyword. The pre-existing normalization collapsed only `[\\t\\n]`, so\nliteral spaces \u2014 including folded-header padding \u2014 reached the splitter intact.\n\nMeasured: 24 000 spaces in one `Received:` header \u2192 22 s; ~100 KB \u2192 minutes.\n\n### Impact\n\nAvailability. A handful of small emails keeps every parsing worker of a mail\ngateway, ticketing system, quarantine UI, or archiving pipeline permanently\nbusy. No confidentiality or integrity impact.\n\nAnyone who parses email they did not author is affected \u2014 which is the library\u0027s\npurpose.\n\n### Patches\n\nFixed in **4.6.1**.\n\n- The address fallback is now a linear scan: the header is split into\n  comma-separated items (quote-aware, in Python), then each item is matched\n  against a bounded angle-address `\u003c([^\u003c\u003e\\s]+)\u003e` with the display name derived\n  in Python, falling back to a bare-email match. Each pattern has a single\n  non-nested quantifier over a negated character class \u2192 O(n).\n  2000 padding spaces: `3.5 s \u2192 \u003c0.01 s`. 256 KB padding: `hours \u2192 0.087 s`.\n  Output is preserved on every previously supported shape.\n- `parse_received()` collapses whitespace runs to a single space before\n  splitting, so the splitter\u0027s `\\s+` only ever matches one character \u2192 O(n).\n  The date is extracted from the raw header beforehand, so date formatting is\n  unaffected. 24 000 spaces: `22 s \u2192 0.003 s`; 200 000 spaces: `0.004 s`.\n\nRegression tests assert linear-time behaviour for both paths.\n\n### Workarounds\n\nNone within the library. Upgrade to `4.6.1`.\n\nUsers who cannot upgrade immediately should cap total header size before\nparsing and enforce a wall-clock timeout around each parse.",
  "id": "GHSA-r7w7-vpq8-c5vv",
  "modified": "2026-11-16T22:11:08Z",
  "published": "2026-11-16T22:11:08Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/SpamScope/mail-parser/security/advisories/GHSA-r7w7-vpq8-c5vv"
    },
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-129295"
    },
    {
      "type": "WEB",
      "url": "https://github.com/SpamScope/mail-parser/pull/166"
    },
    {
      "type": "WEB",
      "url": "https://github.com/SpamScope/mail-parser/commit/037293158cb291caa96635a54449243d32cd4d96"
    },
    {
      "type": "WEB",
      "url": "https://github.com/SpamScope/mail-parser/commit/5aab122f0d763991604d2c2bcc807c6bf2489464"
    },
    {
      "type": "WEB",
      "url": "https://github.com/SpamScope/mail-parser/commit/85e53f820d78ae7c955dafbbcd0e20989a735c2c"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/SpamScope/mail-parser"
    },
    {
      "type": "WEB",
      "url": "https://github.com/SpamScope/mail-parser/releases/tag/4.6.1"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
      "type": "CVSS_V3"
    }
  ],
  "summary": "mail-parser is vulnerable to polynomial ReDoS in email header parsing"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.

Loading…

Loading…

Loading…

Related by attack behaviour

Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.


Loading…