Summary
Mistune contains a path traversal vulnerability in its RST include directive that may allow attacker-controlled Markdown to reference files outside the intended content directory.
When such Markdown is rendered, sensitive local files such as credentials or environment data could be embedded in the generated HTML if the application exposes the rendered output.
Mistune contains a path traversal vulnerability in its RST include directive that may allow attacker-controlled Markdown to reference files outside the intended content directory.
When such Markdown is rendered, sensitive local files such as credentials or environment data could be embedded in the generated HTML if the application exposes the rendered output.
Affected context
The issue occurs in applications that use Mistune's RST include directive to render Markdown or reStructuredText content and allow untrusted users or external systems to supply that content. It becomes risky when the include mechanism resolves relative or absolute filesystem paths without adequately restricting them to an approved directory.
The issue occurs in applications that use Mistune's RST include directive to render Markdown or reStructuredText content and allow untrusted users or external systems to supply that content. It becomes risky when the include mechanism resolves relative or absolute filesystem paths without adequately restricting them to an approved directory.
Exploit preconditions
- Attack surface: Markdown or RST content processed by Mistune
- Required access: Ability to submit or influence content that is rendered by the application
- Trigger point: Processing of an include directive during document rendering
- Why exploitation is possible: File paths are resolved without sufficiently enforcing an allowed-root boundary, allowing references outside the intended content area
- Attack surface: Markdown or RST content processed by Mistune
- Required access: Ability to submit or influence content that is rendered by the application
- Trigger point: Processing of an include directive during document rendering
- Why exploitation is possible: File paths are resolved without sufficiently enforcing an allowed-root boundary, allowing references outside the intended content area
Why this happens
The vulnerability is caused by insufficient path validation in the RST include directive. The renderer treats attacker-influenced path values as filesystem locations without reliably canonicalizing them and enforcing containment within an approved directory.
This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where input can influence access to files beyond the intended filesystem boundary.
The vulnerability is caused by insufficient path validation in the RST include directive. The renderer treats attacker-influenced path values as filesystem locations without reliably canonicalizing them and enforcing containment within an approved directory.
This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where input can influence access to files beyond the intended filesystem boundary.
Potential impact
- Sensitive files may be disclosed through rendered HTML
- Credentials, tokens, or environment data could be exposed
- Application configuration and source files may be revealed
- Downstream users or systems can be affected if rendered output is trusted or redistributed
- Sensitive files may be disclosed through rendered HTML
- Credentials, tokens, or environment data could be exposed
- Application configuration and source files may be revealed
- Downstream users or systems can be affected if rendered output is trusted or redistributed
General mitigation guidance
Mitigation generally focuses on reducing trust in document-supplied paths and enforcing a strict filesystem boundary.
Common defensive patterns include:
- Disable include processing for untrusted content when it is not required
- Resolve paths canonically before access and require them to remain within an approved directory
- Prefer allowlisted documents or identifiers over arbitrary filesystem paths
- Apply strict input and content validation before rendering
- Run rendering components with least-privilege filesystem access
- Avoid exposing rendered output containing sensitive server-side content
These controls help limit disclosure risk even if an attacker can influence rendered documents.
Mitigation generally focuses on reducing trust in document-supplied paths and enforcing a strict filesystem boundary.
Common defensive patterns include:
- Disable include processing for untrusted content when it is not required
- Resolve paths canonically before access and require them to remain within an approved directory
- Prefer allowlisted documents or identifiers over arbitrary filesystem paths
- Apply strict input and content validation before rendering
- Run rendering components with least-privilege filesystem access
- Avoid exposing rendered output containing sensitive server-side content
These controls help limit disclosure risk even if an attacker can influence rendered documents.
How teams detect issues like this
Organizations can identify this class of issue through:
- Static analysis and code review checks for filesystem access using document-controlled paths
- Review of include and template features for canonicalization and allowed-root enforcement
- Tests covering boundary paths, symbolic links, absolute paths, and normalization behavior
- Runtime monitoring for unexpected reads outside designated content directories
- Policy enforcement that disables filesystem-backed directives for untrusted document sources
Automated security review tools may help flag path construction and file access patterns that lack containment checks.
Organizations can identify this class of issue through:
- Static analysis and code review checks for filesystem access using document-controlled paths
- Review of include and template features for canonicalization and allowed-root enforcement
- Tests covering boundary paths, symbolic links, absolute paths, and normalization behavior
- Runtime monitoring for unexpected reads outside designated content directories
- Policy enforcement that disables filesystem-backed directives for untrusted document sources
Automated security review tools may help flag path construction and file access patterns that lack containment checks.

