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
-
Install vulnerable version:
pip install mistune==3.2.0
-
Run the following code:
import mistune
markdown = mistune.create_markdown() html = markdown("j")
print(html)
-
Output:
<p><a href="javascript%3Aalert(1)">j</a></p> -
Open the rendered HTML in a browser and click the link.
-
The browser decodes "%3A" into ":" and executes:
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:
- Session hijacking (e.g., cookie theft)
- Execution of arbitrary JavaScript in the victim's context
- Potential account takeover depending on the application
This affects any application that renders user-controlled Markdown using Mistune without additional URL sanitization.
Affected software
Click a technology to see all vulnerabilities affecting it.
| Platform | Package | Vulnerable versions | Fixed in |
|---|---|---|---|
| Python (PyPI) | mistune | < 3.3.0 | 3.3.0 |
References
- https://github.com/lepture/mistune/releases/tag/v3.3.0
- https://github.com/lepture/mistune/commit/c7101fcbb6e8790e8e39157c5ca2238fc6dd6cbc
- https://github.com/lepture/mistune/security/advisories/GHSA-8c25-4j27-2rv3
- https://nvd.nist.gov/vuln/detail/CVE-2026-59923
- https://github.com/lepture/mistune
- https://github.com/pypa/advisory-database/tree/main/vulns/mistune/PYSEC-2026-2211.yaml
- CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N- Weakness (CWE)
CWE-79- Platform
- Python (PyPI)
- Package
mistune- Disclosed
- 08.07.2026
- Updated
- 11.10.2026 14:18
Sources and licenses
OSV / GitHub Advisory Database - PYSEC-2026-2211 - PyPA Advisory Database; CC BY 4.0
OSV / GitHub Advisory Database - GHSA-8c25-4j27-2rv3 - CC BY 4.0
Vulnerability history: mistune
All published vulnerabilities of this package (Python (PyPI)), newest first. Shows whether this is a one-off slip or a package that needs watching.
- Total entries
- 20
- First → latest
- 10.2017 09.2026
- Without a fix
- 1
- Exploited in attacks
- 0
Severity breakdown
- High 7
- Medium 13
Disclosures per year
- 2017: 2
- 2018: 0
- 2019: 0
- 2020: 0
- 2021: 0
- 2022: 1
- 2023: 0
- 2024: 0
- 2025: 0
- 2026: 17
-
Mistune: XSS via percent-encoded javascript URI bypass in safe_url() this entry
Know which vulnerabilities affect your application
With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.