Mistune Markdown Parser Math Plugin XSS Escape Bypass Vulnerability

Vulnerability

A cross-site scripting (XSS) vulnerability has been identified in the Mistune math plugin, which is a Python Markdown parser. The issue arises in versions prior to 3.2.1, where the math plugin renders inline ($...$) and block math ($$...$$) by directly concatenating user-supplied content into the HTML output without proper HTML escaping. This flaw occurs even when the parser is configured to escape content, leading to a violation of the expected XSS protection. The vulnerability allows an attacker to inject malicious scripts that could be executed in the context of the user's browser.

Impact

Exploitation of this vulnerability allows for cross-site scripting, where injected scripts are executed in the context of the user's browser. This could lead to exfiltration of session cookies, authentication tokens, and other data visible in the victim's browser session. Additionally, it could allow for manipulation of page content, injection of phishing forms, redirection of users, or execution of authenticated actions. There is also a potential denial-of-service impact, where the injected script could crash or freeze the page for the user.

Reproduction

To reproduce this vulnerability, create a Markdown parser with the math plugin enabled and the escape option set to true. Then, input raw HTML, such as a script tag, which will be correctly escaped. Next, input the same HTML payload within inline math delimiters. The output will show that the HTML has been rendered raw, unescaped, and executed as a script. This bypass also works with block math, where similar payloads can be injected and executed.

Remediation

Users can upgrade to Mistune version 3.2.1 or later, where this vulnerability has been fixed.

Added: May 26, 2026, 9:51 PM
Updated: May 26, 2026, 9:51 PM

Vulnerability Rating

Custom Algorithm
spread
5.4
impact
1.7
exploitability
5.8
remediation
7.7
relevance
9.6
threat
6.4
urgency
2.9
incentive
0.0

Our algorithm analyzes dozens of metrics to generate these 8 key vulnerability categories, which are then combined to calculate the overall risk score.