Executive brief
Mistune is a popular Python library used to convert Markdown text into HTML. A security flaw in how it handles image figures allows an attacker to inject malicious scripts into web pages. If a user views a page containing specially crafted Markdown, the attacker could potentially steal session information or perform actions on the user's behalf.
Technical details
A cross-site scripting (XSS) vulnerability exists in Mistune's `render_figure()` function within `src/mistune/directives/image.py`. The function fails to escape the `figclass` and `figwidth` options before concatenating them into HTML attributes, leading to attribute injection. This bypasses the standard `HTMLRenderer(escape=True)` setting because these specific directive values are handled outside the primary inline renderer. An attacker can exploit this by providing a malicious Markdown figure directive that includes JavaScript or other malicious HTML attributes. The issue is fixed in version 3.2.1.
Affected products
- lepture mistune <= 3.2.0
Timeline
- 2026-05-06: disclosed
- 2026-05-08: advisory: GitHub Advisory published
- 2026-05-26: advisory: NVD published
References
- https://api.github.com/users/sergeykochanov
- https://github.com/sergeykochanov
- https://api.github.com/users/sergeykochanov/gists%7B/gist_id%7D
- https://api.github.com/users/sergeykochanov/repos
- https://avatars.githubusercontent.com/u/47022537?v=4
- https://api.github.com/users/sergeykochanov/events%7B/privacy%7D