VAITP Dataset

← Back to the dataset

CVE-2026-59923

Mistune vulnerable to XSS via percent-encoded javascript URIs in links.

  • CVSS 6.1
  • CWE-79
  • Input Validation and Sanitization
  • Remote

Mistune is a Python Markdown parser with renderers and plugins. Prior to 3.3.0, HTMLRenderer.safe_url() does not block percent-encoded javascript URIs, allowing attacker-supplied Markdown links or images to bypass URL protections and execute script in rendered HTML. This issue is fixed in version 3.3.0.

CVSS base score
6.1
Published
2026-07-08
OWASP
A03 Injection
Orthogonal defect classification
Checking
Code defect classification
Incorrect Check
Category
Input Validation and Sanitization
Subcategory
Cross-Site Scripting (XSS)
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Mistune
Fixed by upgrading
Yes

Solution

Upgrade Mistune to version 3.3.0 or later.

Vulnerable code sample

import mistune

# This example demonstrates the behavior of a vulnerable version of mistune (e.g., < 2.0.3)
# which is susceptible to a vulnerability similar to the one described.
# The payload uses a percent-encoded "javascript:" URI to bypass sanitization.
# %6a%61%76%61%73%63%72%69%70%74: is the encoding for "javascript:"
malicious_text = "[Click me for a surprise](%6a%61%76%61%73%63%72%69%70%74:alert('XSS'))"

# On a vulnerable version, the default HTMLRenderer's safe_url() method
# would fail to recognize and block the percent-encoded URI scheme.
markdown_parser = mistune.Markdown()

# The parser processes the markdown and outputs an HTML string.
rendered_html = markdown_parser(malicious_text)

# The resulting HTML contains an href attribute with the malicious javascript URI.
# When rendered in a browser, clicking this link would execute the script.
# Expected vulnerable output: <p><a href="javascript:alert('XSS')">Click me for a surprise</a></p>
print(rendered_html)

Patched code sample

import re
from urllib.parse import unquote

# The vulnerability described is officially tracked as CVE-2022-34749,
# which was fixed in mistune v2.0.3. The provided code is based on that
# official fix, as it directly addresses the percent-encoding bypass.

class HTMLRenderer:
    """A mock renderer class to contain the fixed method."""
    HARMFUL_PROTOCOLS = {
        'javascript:',
        'vbscript:',
        'data:',
    }

    def __init__(self, escape=True, allow_harmful_protocols=None):
        self._escape = escape
        self.allow_harmful_protocols = allow_harmful_protocols

    def safe_url(self, url: str) -> str:
        """Sanitize URL to prevent XSS attacks.

        This is the fixed version of the method. It unquotes the URL
        before checking for harmful protocols, preventing schemes like
        'j%61vascript:' from bypassing the filter.
        """
        if self.allow_harmful_protocols is None:
            schemes = self.HARMFUL_PROTOCOLS
        elif self.allow_harmful_protocols is True:
            schemes = set()
        else:
            schemes = self.HARMFUL_PROTOCOLS - self.allow_harmful_protocols

        if schemes:
            # prevent XSS, example: javascript:alert(1)
            # The fix is to unquote the URL before checking the scheme
            _url = unquote(url).lower()
            for s in schemes:
                if _url.startswith(s):
                    return '#harmful-link'
        return url

Payload

[Click me](%6a%61%76%61%73%63%72%69%70%74%3aalert(1))

Cite this entry

@misc{vaitp:cve202659923,
  title        = {{Mistune vulnerable to XSS via percent-encoded javascript URIs in links.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-59923},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-59923/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::