Executive brief
Mistune is a Python library used to convert Markdown text into HTML. A vulnerability in its Table of Contents (TOC) feature uses predictable numbering for section links, which allows an attacker to inject malicious content that hijacks these links. This could lead to users being redirected to the wrong part of a page or breaking the functionality of website navigation and accessibility tools.
Technical details
The Mistune 'toc' plugin and 'TableOfContents' directive use a predictable identifier generation scheme for heading IDs, defaulting to a simple 'toc_N' format based on document position rather than content. An attacker who can influence the document content (e.g., through unsanitized HTML or specific directives) can inject elements with matching IDs earlier in the DOM. This causes a collision where browsers, CSS, and JavaScript selectors may prioritize the attacker's element over the legitimate heading. This can be used to hijack internal anchor navigation, redirect click handlers, or break ARIA associations. The issue is fixed in version 3.3.0 by implementing text-based slugification for IDs.
Affected products
- lepture mistune < 3.3.0
Timeline
- 2026-06-21: disclosed
- 2026-07-20: advisory
- 2026-07-20: patched: Fixed in version 3.3.0