Executive brief
Mistune, a popular Python library used to convert Markdown text into HTML, contains a security flaw in how it generates Tables of Contents (TOC). If an application uses Mistune to process user-provided content, an attacker can craft a malicious heading that injects unauthorized scripts into the page. This could allow an attacker to steal user session data or perform actions on behalf of other users viewing the generated document.
Technical details
A Cross-Site Scripting (XSS) vulnerability exists in Mistune's `render_toc_ul()` function within `src/mistune/toc.py`. The function builds a Table of Contents tree using a Python format string that fails to apply HTML escaping to the 'id' and 'text' values used in anchor tags. When heading IDs are derived from user-supplied text (a common pattern for slug-based anchors), an attacker can provide a heading that breaks out of the `href` attribute context. This allows for the injection of arbitrary HTML and `<script>` blocks. The issue is resolved in version 3.2.1 by ensuring proper escaping of heading IDs and text.
Affected products
- lepture Mistune < 3.2.1
Timeline
- 2026-05-03: patched: Version 3.2.1 released with HTML escaping fixes.
- 2026-05-12: advisory: GitHub Security Advisory GHSA-6269-cqxg-mhhv published.
- 2026-05-26: disclosed: CVE-2026-44898 published to the NVD.