CVE-2026-44708
Mistune's math plugin is vulnerable to XSS via unsanitized expressions.
- CVSS 6.1
- CWE-79
- Input Validation and Sanitization
- Remote
Mistune is a Python Markdown parser with renderers and plugins. Prior to 3.2.1, the mistune math plugin renders inline math ($…$) and block math ($$…$$) by concatenating the raw user-supplied content directly into the HTML output without any HTML escaping. This occurs even when the parser is explicitly created with escape=True, which is supposed to guarantee that all user-controlled text is sanitised before reaching the DOM. This vulnerability is fixed in 3.2.1.
- CWE
- CWE-79
- CVSS base score
- 6.1
- Published
- 2026-05-26
- OWASP
- A03 Injection
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing 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.2.1 or later.
Vulnerable code sample
import mistune
from mistune.plugins import plugin_math
# This code must be run with a vulnerable version of mistune (e.g., 3.2.0 or older).
# Malicious input with an XSS payload inside an inline math block.
malicious_markdown_input = "An equation: $<img src=x onerror=alert('XSS')>$"
# Initialize the parser with escape=True and the math plugin.
# In vulnerable versions, the escape=True flag is ignored for content
# within math blocks, leading to the vulnerability.
markdown_parser = mistune.create_markdown(
escape=True,
plugins=[plugin_math()]
)
# Render the markdown to HTML.
vulnerable_html_output = markdown_parser(malicious_markdown_input)
# In a vulnerable version, this will print HTML containing the unescaped <img> tag,
# which would execute the script in a browser.
# Expected vulnerable output: <p>An equation: <span class="math" role="math"><img src=x onerror=alert('XSS')></span></p>
print(vulnerable_html_output)Patched code sample
import mistune
from mistune.plugins import plugin_math
# The CVE describes a vulnerability where content within math blocks ($$...$$)
# was not HTML-escaped, even when the parser was initialized with `escape=True`.
# This example demonstrates the behavior of a *fixed* version of mistune.
# Malicious input that would cause an XSS vulnerability in unpatched versions.
# The payload is inside a math block, which was not being escaped.
malicious_markdown_with_math = "Equation: $$<img src=x onerror=alert('XSS')>$$"
# In a patched version of mistune, creating the parser with `escape=True`
# now correctly applies HTML escaping to the content within math blocks.
# This is the essence of the fix.
safe_parser = mistune.create_markdown(
escape=True, # This parameter is now correctly respected by the math plugin.
plugins=[
plugin_math,
]
)
# When this markdown is parsed by the fixed version, the malicious HTML is sanitized.
safe_html_output = safe_parser(malicious_markdown_with_math)
# The resulting `safe_html_output` will contain the escaped HTML, e.g.:
# '<div class="math">$$<img src=x onerror=alert('XSS')>$$</div>'
# This prevents the browser from interpreting the <img ...> tag and executing
# the malicious script, thus mitigating the vulnerability.
# To verify, you can print the output:
# print(safe_html_output)Payload
$<img src=x onerror=alert('XSS')>
Cite this entry
@misc{vaitp:cve202644708,
title = {{Mistune's math plugin is vulnerable to XSS via unsanitized expressions.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-44708},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-44708/}}
}
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 ::
