mistune
Affected
- introduced
0, fixed3.3.0(ecosystem)
Fixed versions
3.3.0
Fix
- Fixed version
3.3.0pip install --upgrade mistune==3.3.0
Advisory
Also known as: CVE-2026-59923, PYSEC-2026-2211
Mistune: XSS via percent-encoded javascript URI bypass in safe_url()
Summary
An XSS vulnerability in Mistune allows bypassing of safe_url() protections via percent-encoded javascript URIs.
Details
The vulnerability exists in HTMLRenderer.safe_url() in Mistune.
The function is intended to block harmful URL schemes such as "javascript:" by checking the prefix of the provided URL:
_url = url.lower()
if _url.startswith(self.HARMFUL_PROTOCOLS):
return "#harmful-link"
However, the input URL is not URL-decoded before this check. Because of this, an attacker can use percent-encoding to bypass the filter. For example:
javascript%3Aalert(1)
Since "%3A" is not decoded to ":", the check does not detect the "javascript:" scheme.
When rendered in a browser, the URL is decoded, resulting in execution of arbitrary JavaScript upon user interaction.
This effectively bypasses Mistune's built-in safe_url() protection mechanism.
PoC
pip install mistune==3.2.0
import mistune
markdown = mistune.create_markdown()
html = markdown("[j](javascript%3Aalert(1))")
print(html)
<p><a href="javascript%3Aalert(1)">j</a></p>
javascript:alert(1)
Impact
This is a cross-site scripting (XSS) vulnerability.
An attacker can craft a malicious Markdown link that executes JavaScript in the victim's browser when clicked.
Impact includes:
This affects any application that renders user-controlled Markdown using Mistune without additional URL sanitization.
Medium Basis: The source's own band: MODERATE
0, fixed 3.3.0 (ecosystem)3.3.0
3.3.0pip install --upgrade mistune==3.3.0Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.
Check your own computer: guard packages check
Source: GitHub Advisory Database (reviewed advisories) · CC BY 4.0