GHSA-MX3X-26CX-VW34
Quadratic body URL re-extraction causes CPU denial of service when parsing e-mails with many URLs
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-MX3X-26CX-VW34 divulgada · CVSS 5.3 (GitHub) | |
| Remediación | Parche 3.0.5 | eml-parser · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
## CVE Description
EmlParser.parse_email() in eml-parser (Python package eml_parser) versions 3.0.2 through 3.0.4 re-scans the entire accumulated list of previously discovered URLs on every slice of a message body when extracting domains, resulting in quadratic $O(n^2)$ processing time in the number of URLs present in the body. An unauthenticated attacker who can submit a crafted .eml file to a service that parses it can cause sustained CPU exhaustion (denial of service) of the parsing component.
Summary
When `eml_parser` extracts URLs and domains from a message body, it re-scans the entire accumulating list of previously discovered URLs on every sliding-window slice of the body, rather than only the URLs found in the current slice. For a body containing many distinct valid URLs, this repeated re-scan produces O(n^2) work in the body size. An unauthenticated attacker who supplies a crafted `.eml` file to any service that calls the public parsing API can pin a CPU core for an extended period, producing an availability denial of service. The behavior is independent of the regex engine and is present in the default installation.
Root Cause
The body parser declares two URL accumulator lists once per body part, then iterates the body in fixed-size slices. Inside the per-slice loop it appends the URLs found in the current slice to the accumulators, and then, in the same loop iteration, re-iterates the full accumulated lists to re-extract domains from every URL discovered so far. Because deduplication is only applied after the loop finishes, the accumulators grow monotonically and each slice re-processes all earlier URLs. The security invariant that body processing should cost time bounded linearly by the body size is violated: total re-extraction work is proportional to the sum over slices of the URLs seen so far, which is O(URLs times slices), i.e. quadratic in the body length.
Affected components:
- eml_parser/parser.py: EmlParser.parse_email
- Accumulator lists declared outside the slice loop (parser.py:474-475)
- Per-slice appends with no in-loop dedup (parser.py:486, 488)
- Per-slice re-extraction over the full accumulated lists (parser.py:502-506)
- Deduplication only after the loop (parser.py:519, 522)Impact
An unauthenticated attacker who can deliver an `.eml` to a service that parses it can cause sustained single-core CPU exhaustion. The issue is reachable in the default configuration: the body extraction loop runs unconditionally, and the reporting flag `include_raw_body` gates only whether results are reported, not whether extraction runs. Demonstrated: a body of about 107 KB composed of distinct valid URLs takes roughly 4.3 seconds of one core in the released version, with clean quadratic scaling. Because the cost is quadratic, a multi-megabyte body (within limits many mail systems permit) plausibly scales to minutes of CPU per message, and repeated or concurrent submissions can plausibly deny service to the parsing component. The impact is limited to availability; no confidentiality or integrity effect was observed or is implied. This behavior does not depend on the regex engine and reproduces with or without the optional regex extra.
Proof of Concept
Requires Python 3.10+ and eml-parser installed from a release in the affected range (e.g. pip install eml-parser==3.0.4).
import time
import eml_parser
def body_with_valid_urls(n_urls: int) -> bytes:
return ' '.join(f'http://h{i}.example.com/p' for i in range(n_urls)).encode()
def parse(body: bytes) -> float:
raw = b'From: sender@example.com\r\nSubject: poc\r\n\r\n' + body + b'\r\n'
t0 = time.perf_counter()
eml_parser.EmlParser().decode_email_bytes(raw)
return time.perf_counter() - t0
for n in (500, 1000, 2000, 4000):
body = body_with_valid_urls(n)
print(f'urls={n:5d} body={len(body):7d}B parse={parse(body):8.3f}s')urls= 500 body= 12889B parse= 0.100s
urls= 1000 body= 25889B parse= 0.316s
urls= 2000 body= 52889B parse= 1.143s
urls= 4000 body= 106889B parse= 4.306s
negative control (4000 URLs that fail validation, body=46889B): 0.064sThe clean fourfold growth per doubling confirms O(n^2) cost; the negative control (URLs that fail domain validation and therefore do not accumulate) isolates the accumulator re-scan, not any single per-slice extraction, as the cost driver.
Attack Chain
- Exposure: An unauthenticated attacker delivers an `.eml` whose body is a long list of distinct valid URLs to a service that calls the public API `EmlParser().decode_email_bytes()` or `.decode_email()`, reaching `parse_email()` and the body loop (parser.py:470).
- Control: The body is fully attacker controlled. Each URL only needs a valid registrable domain (for example `http://hN.example.com/p`) to pass validation and accumulate; the attacker can supply arbitrarily many distinct such URLs.
- Path: The body is iterated in fixed-size slices (parser.py:483). Each slice appends its URLs to the accumulator lists declared outside the loop (parser.py:474-475, appended at :486 and :488), then re-iterates the full accumulated lists to re-extract domains (parser.py:502-506).
- Guard: The slicing bounds each individual extraction but does not bound the re-iteration of the growing accumulator, which is the sink. Deduplication is applied only after the loop (parser.py:519, 522), so in-loop the lists grow monotonically with no cap and no dedup.
- Primitive: Total re-extraction work is proportional to the sum over slices of the URLs seen so far, giving O(body^2) CPU work.
- Result: One CPU core is pinned for the duration (about 4.3 seconds for a 107 KB body, scaling quadratically), denying timely service to the parsing component.
Affected Versions
- `Ecosystem: pip (PyPI)`
- `Package: eml-parser`
- `Confirmed affected range: >= 3.0.2, <= 3.0.4`
- `Latest release checked: 3.0.4 (PyPI, matching the tagged source)`
- `Fix status: fixed in > 3.0.4`
The vulnerable loop was introduced in version 3.0.2 (verified: absent at v3.0.1, present at v3.0.2, introduced by the v3.0.2-tagged commit) and remains present through the latest release 3.0.4. The behavior is independent of configuration and of the optional `regex` extra.
Remediation
Upgrade eml-parser to a fixed version, in which domains are re-extracted once, from the deduplicated URL set, after the slicing loop completes, making body extraction linear in body size. As an interim mitigation without a code change, operators can cap the maximum message and body size accepted upstream of the parser.
Reported by zx (GitHub: @manus-pi).
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
pypieml-parser |
Corregida | 3.0.5 | 0 d | 4.7.0 no afectada |
3.0.5Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/GOVCERT-LU/eml_parser/security/advisories/GHSA-mx3x-26cx-vw34Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
