GHSA-J5PM-9MX9-PGGQ
Exponential ReDoS in pymdownx.blocks.html/caption selector parsing enables unauthenticated remote DoS
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:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Remediación | Parche 11.0.2 | pymdown-extensions · -77 d desde divulgación | |
| Divulgación | Publicada | GHSA-J5PM-9MX9-PGGQ divulgada · CVSS 7.5 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
## Summary
`pymdownx.blocks.html` (and `pymdownx.blocks.caption`) are vulnerable to exponential catastrophic backtracking (ReDoS) when parsing a block's CSS-style selector argument. A sub-60-byte block pins the render thread at 100% CPU for tens of seconds, enabling unauthenticated remote denial of service anywhere untrusted Markdown is rendered with the extension enabled.
## Root Cause
A generic block `/// html | <ARG>` passes the fully attacker-controlled selector `<ARG>` to `parse_selectors()` (`pymdownx/blocks/html.py:152` via `HTML.on_validate`; `caption.py:243` via `Caption.on_validate` with `require_tag=False`). `parse_selectors` runs `RE_ATTRS`/`RE_ATTR` built from two catastrophic-backtracking regexes:
- `PAT_ATTR` (html.py:31-33): `\[(?:{ws}*(?P<attr_name>{ident}){attr})+{ws}*\]` — an outer `+` over an attribute whose `=value` is optional and whose `{ident}` is itself a `(...)+`/`(...)*` over overlapping classes. An unterminated `[aaaa…` makes the outer `+` and the inner identifier repeats partition the run exponentially.
- `VALUE` (html.py:18-20): `(?:\\(?:.)|[^\\"\r\n\f]+)*?` — a classic `(A|B+)*?` nested quantifier (greedy `+` inside a lazy `*?` over the same char set). An unterminated quoted value `"aaaa…` explodes.
## Impact
Unauthenticated remote DoS (CWE-1333). Distinct from CVE-2025-68142 (which is the polynomial `RE_FIG_NUM` at `caption.py:35`, a different regex). Any service rendering untrusted Markdown with `pymdownx.blocks.html` or `pymdownx.blocks.caption` enabled (default options) hangs.
Proof of Concept
import markdown
s = '/// html | div[' + 'a'*20 + '\n\ncontent\n///\n' # 49-byte selector
markdown.markdown(s, extensions=['pymdownx.blocks.html']) # ~37 s
# Caption path (require_tag=False, needs leading '['):
# s = '/// caption | [' + 'a'*18 + '\n\ncontent\n///\n'## Attack Chain
1. Entry: `markdown.markdown('/// html | div[' + 'a'*20 + '\n\ncontent\n///\n', extensions=['pymdownx.blocks.html'])`. Guard: `RE_START` (blocks/__init__.py:28-30) requires only a valid block name (`html`); the `div` tag and `[…]` selector are never length-bounded or validated. Bypass proof: end-to-end hang, table below.
2. Regex: `parse_selectors` calls `RE_ATTRS.match`/`RE_ATTR.search` (html.py:64/81/101) on the unterminated selector and backtracks over all partitions. Guard: none — no atomic groups, no possessive quantifiers, no length bound on `self.argument`. Sink = html.py:18-33. Bypass proof: raw `RE_ATTRS.match`/`VALUE` isolation shows the same exponential curve independent of markdown overhead.
3. Impact: render thread pegged for seconds→minutes on a <60-byte input → DoS. Reachable via both `blocks.html` and `blocks.caption`.
## Bypass Evidence
Measured via `markdown.markdown(...)`, DEFAULT config:
Variant A '/// html | div[' + a*n: n=18 len=47 5.39 s; n=20 len=49 37.10 s
Variant B '/// html | div[a="' + a*n: n=26 len=58 5.41 s; n=28 len=60 21.32 s
Caption '/// caption | [' + a*n: n=18 len=47 5.38 sControl (`extensions=[]`): 0.0004 s — proves backtracking originates in the finding's regexes. Constant per-increment multiplier (~6.8×/+2 chars) confirms exponential, not polynomial.
## Affected Versions
`<= 11.0.1` (latest release). Fix commit c684985 (CVE-2026-67422) never audited the `blocks` package; these regexes are untouched. No fix on HEAD.
Mitigation
If you feel you are affected by this, or you cannot tolerate the risk, the HTML Blocks extension is an option extension that can be disabled.
## Suggested Fix
Collapse `VALUE`'s overlapping alternation to a single non-overlapping class (`"(?:\\.|[^\\"\r\n\f])*?"`, dropping the inner `+`) and de-ambiguate/bound `PAT_ATTR`'s outer/inner repeats, mirroring the c684985 approach of eliminating partition ambiguity.
---
Reported by zx (Jace) — GitHub: @manus-use
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 |
|---|---|---|---|---|
pypipymdown-extensions |
Corregida | 11.0.2 | -77 d | 13.1.0 no afectada |
11.0.2Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/facelessuser/pymdown-extensions/security/advisories/GHSA-j5pm-9mx9-pggqLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
