Summary
django-docutils can process attacker-influenced reStructuredText with Docutils features and output handling that may expose files, make server-side requests, or preserve script-capable markup. The risk arises when an application renders lower-trust content through the affected rendering paths; applications rendering only trusted static reStructuredText are not affected unless that content can be influenced by an attacker.
Affected context
The issue occurs in django-docutils rendering paths that process reStructuredText, including publishing helpers, template integrations, DocutilsTemplates, and DocutilsView. Risk depends on whether lower-trust content can reach these paths and whether Docutils file insertion, raw content, configuration processing, or unsafe URI handling is permitted without consistent doctree sanitization.
Exploit preconditions
- Attack surface: An application uses an affected django-docutils rendering path.
- Required access: An attacker can supply or influence reStructuredText that the application renders.
- Trigger point: The application processes that content through a publishing helper, template tag or filter, DocutilsTemplates, or DocutilsView.
- Why exploitation is possible: Rendering may allow file-insertion directives, raw content, ambient Docutils configuration, or unsafe URI schemes without consistently sanitizing the resulting doctree.
Why this happens
Lower-trust reStructuredText is passed to Docutils without consistently restricting its active features or sanitizing its output. Directives such as file insertion can expose local content, while raw markup and unsafe URI output can result in script-capable rendered content. This primarily maps to CWE-79: Cross-Site Scripting, with related risks involving path traversal, information exposure, and server-side request forgery.
Potential impact
- An attacker may cause local files to be included in rendered output.
- The application could make server-side requests to attacker-influenced destinations.
- Stored script-capable content may execute in users' browsers when rendered.
- Sensitive information may be disclosed, depending on accessible files and rendering behavior.
General mitigation guidance
Defensive approaches focus on reducing trust in supplied reStructuredText and limiting what the renderer can do.
- Prefer secure-by-default parsing and rendering configurations that disable file insertion and raw content when they are not needed.
- Apply consistent sanitization to doctrees and rendered output, including URI scheme allowlists appropriate to the output context.
- Avoid processing ambient configuration from untrusted or uncontrolled locations.
- Validate content against a constrained schema or supported subset before rendering.
- Run rendering components with least privilege and limit their access to local files and network destinations.
How teams detect issues like this
- Use static analysis to identify Docutils calls and rendering paths that accept lower-trust content without restrictive settings or sanitization.
- Review template tags, filters, publishing helpers, and view integrations for trust boundaries and output-context handling.
- Check configuration and policy controls for file insertion, raw directives, URI schemes, and ambient Docutils configuration.
- Use automated review tools and tests with representative untrusted content to verify that disallowed directives and markup are rejected or safely rendered.

