Medium

Mistune: Arbitrary File Read via Include directive path traversal

  • Disclosed: 08.07.2026
  • Updated: 11.10.2026 14:18

Summary

A path traversal issue exists in mistune's Include directive when markdown files are processed using md.read(). A crafted include path can cause files outside the intended markdown directory to be accessed.

Details

The issue occurs in the Include.parse() method where user-supplied paths are joined and normalized without verifying that the resulting path remains within an expected directory.

python
relpath = self.parse_title(m)
dest = os.path.join(os.path.dirname(source_file), relpath)
dest = os.path.normpath(dest)

Because the final path is not restricted to a trusted base directory, path traversal sequences such as ../ may reference files outside the intended location.

Proof of Concept

Create a markdown file:

markdown
.. include:: ../../../example.txt

Process it using:

python
import mistune
from mistune.directives import RSTDirective, Include

md = mistune.create_markdown(
    plugins=[RSTDirective([Include()])]
)

result, state = md.read("test.md")
print(result)

Impact

Applications that process untrusted markdown files with the Include directive enabled may allow unintended file access. The impact depends on how the feature is used and what files are accessible to the running process.

Recommended Fix

Validate the resolved path and ensure it remains within an allowed directory before opening the file.

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
Python (PyPI) mistune < 3.3.0 3.3.0

References

CVSS score 5.9/10
CVSS vector
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N
Weakness (CWE)
CWE-22
Platform
Python (PyPI)
Package
mistune
Disclosed
08.07.2026
Updated
11.10.2026 14:18

Sources and licenses

OSV / GitHub Advisory Database - PYSEC-2026-2212 - PyPA Advisory Database; CC BY 4.0

OSV / GitHub Advisory Database - GHSA-r4rv-85jg-w4mf - CC BY 4.0

Vulnerability history: mistune

All published vulnerabilities of this package (Python (PyPI)), newest first. Shows whether this is a one-off slip or a package that needs watching.

All (20) in the archive
Total entries
20
First → latest
10.2017 09.2026
Without a fix
1
Exploited in attacks
0

Severity breakdown

  • High 7
  • Medium 13

Disclosures per year

  1. 2017: 2
  2. 2018: 0
  3. 2019: 0
  4. 2020: 0
  5. 2021: 0
  6. 2022: 1
  7. 2023: 0
  8. 2024: 0
  9. 2025: 0
  10. 2026: 17
Severity:
  1. Mistune: Arbitrary File Read via Include directive path traversal this entry
    Medium · 5.9 CVE-2026-59924 < 3.3.0 3.3.0
  2. High · 8.6 CVE-2022-34749 >= 2.0.0a1, < 2.0.3 2.0.3

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.