Summary
NiceGUI's ui.restructured_text() renders user-supplied reStructuredText on the server with Docutils while leaving file inclusion directives enabled, allowing template content to reference local files.
If an application passes attacker-controlled text into ui.restructured_text(), an attacker can cause the server to embed the contents of local files that are readable by the NiceGUI process into the rendered output.
Affected context
This vulnerability exists in NiceGUI applications that:
- Use
ui.restructured_text()to render reStructuredText on the server, and - Accept and forward user-controlled or otherwise untrusted text into that API, and
- Run the NiceGUI server with access to sensitive local files (configuration, secrets, logs, or source code).
Applications that only ever render fixed, trusted strings through ui.restructured_text() are not directly impacted by this issue.
Exploit preconditions
- Attack surface: HTTP(S) endpoints or UI interactions that accept text input and pass it to
ui.restructured_text(). - Required access: Ability to supply or influence the reStructuredText content rendered by the server (e.g., form input, database-stored content, CMS-like features, chat/comments).
- Trigger point: Server-side rendering of reStructuredText via Docutils when the content contains file-related directives (such as
.. include::,.. csv-table::with:file:, or.. raw::with:file:). - Why exploitation is possible: Docutils is invoked with file insertion directives enabled, so the renderer treats directive arguments as file paths relative to the server and reads those files into the rendered output without enforcing a strict allowlist of safe locations.
Why this happens
The underlying issue is the server-side rendering of a powerful markup language (reStructuredText) with untrusted input, without restricting features that can reach the file system.
Specifically, the NiceGUI ui.restructured_text() helper calls Docutils in a configuration that leaves file insertion directives (e.g., include, csv-table with :file:, raw with :file:) enabled. When attacker-controlled text is passed into this renderer, Docutils will follow these directives and read local files from disk, reflecting their contents in the generated HTML. This maps to CWE-200: Exposure of Sensitive Information to an Unauthorized Actor, because filesystem contents that should remain private become reachable through the application's rendering behavior.
Potential impact
- Disclosure of configuration files containing secrets, tokens, or database credentials that are readable by the NiceGUI process.
- Exposure of application source code, templates, internal documentation, or proprietary logic.
- Leakage of system files and environment details that could assist in further attacks (privilege escalation or lateral movement).
- Access to server logs or debug traces that may include user data or internal error information.
- Chaining with other vulnerabilities (e.g., using stolen credentials or keys) to move from information disclosure to full compromise.
General mitigation guidance
Effective mitigation centers on restricting what the reStructuredText renderer is allowed to do and minimizing trust in user input:
- Disable file and raw directives: Configure Docutils with settings that explicitly disable
include,raw,csv-table :file:, and other directives that perform file I/O or embed arbitrary content. - Use a restricted markup subset: Prefer a safer, limited mode or a wrapper around Docutils that only allows formatting constructs (headings, lists, emphasis) and rejects structural or I/O-related directives.
- Treat user input as untrusted content: Avoid passing user-controlled text directly to
ui.restructured_text(); instead, use plain text rendering or a safer markup format (e.g., Markdown in a restricted mode) for untrusted content. - Constrain server file access: Run the application under a dedicated low-privilege account, use strict filesystem permissions, and isolate sensitive configuration or secrets outside the process-readable path where practical.
- Apply defense-in-depth controls: Enforce principles like least privilege, separation of concerns (e.g., keeping rendering components isolated), and centralized configuration for safe rendering defaults.
How teams detect issues like this
Organizations can identify and monitor this vulnerability pattern using both code-level and operational approaches:
- Static analysis and code search:
- Search for usage of
ui.restructured_text()or direct Docutils calls that process variable or user-supplied content. - Flag code that passes request parameters, form fields, or database-backed user content directly into reStructuredText renderers.
- Detect Docutils configuration that leaves
file_insertion_enabledor similar options in their default (permissive) state. - Code review signals:
- Pay attention to server-side rendering of rich text or markup languages where users control the content.
- Question any use of docutils, reStructuredText, or similar tools in web handlers, templates, or APIs receiving user input.
- Runtime and logging indicators:
- Instrument or log reStructuredText rendering calls, especially when they open files, to detect anomalies or unexpected file paths.
- Monitor for suspicious markup patterns in user submissions (e.g., frequent
.. include::or:file:directives). - Automated tooling:
- Incorporate linters or SAST tools that understand common unsafe Docutils configurations.
- Add CI/CD checks that enforce safe rendering policies and configuration templates for content processing libraries.

