T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/convert.py:126
- Finding
- Untrusted Markdown Is Rendered with Local File Access and Network Resource Loading<![CDATA[ ## Vulnerability Details **File Location**: `scripts/convert.py`, lines 91 and 126–131 **Vulnerability Type**: Unsafe HTML rendering with excessive renderer capabilities **Risk Level**: High ### Vulnerable Code ```python # Convert Markdown to HTML html = markdown.markdown(md_content, extensions=['fenced_code', 'tables']) ``` ```python # Run wkhtmltopdf cmd = [ 'wkhtmltopdf', '--enable-local-file-access', tmp_path, output_path ] result = subprocess.run(cmd, capture_output=True, text=True) ``` ### Technical Analysis The Markdown input is converted to HTML without sanitizing raw HTML elements, attributes, scripts, or resource URLs. Python-Markdown preserves raw HTML by default, so attacker-controlled HTML can reach the generated temporary document. The document is then processed by `wkhtmltopdf` with `--enable-local-file-access`. JavaScript and network resource loading are not explicitly disabled. Consequently, crafted Markdown may cause the renderer to process local `file://` references or issue requests to attacker-selected, internal, or external URLs through elements such as images, frames, stylesheets, or scripts. There is no validation of URL schemes, target hosts, local paths, or resource types before rendering. The command uses an argument list rather than a shell command, so this is not shell-command injection; the vulnerability is the excessive file and network access granted to a renderer processing attacker-controlled content. ### Attack Path 1. An attacker supplies a Markdown document containing raw HTML or Markdown resource references. 2. The document references a sensitive local path, internal service, cloud metadata endpoint, or attacker-controlled server. 3. Python-Markdown preserves or generates the resource reference in the HTML document. 4. The application invokes `wkhtmltopdf` with local-file access enabled and without disabling JavaScript or external network access. 5. The renderer attempts to access the refe ...[truncated 1044 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove `--enable-local-file-access` unless local resource loading is strictly required. 2. Disable JavaScript explicitly with `--disable-javascript`. 3. Sanitize generated HTML using a maintained allowlist-based sanitizer. Remove raw scripts, frames, embedded objects, event-handler attributes, dangerous URI schemes, and other active content. 4. Validate all resource references and permit only required schemes and trusted destinations. Reject `file:`, loopback, link-local, private-network, and cloud metadata addresses. 5. Block outbound network access for the renderer at the operating-system or container level. 6. Run conversion in a dedicated sandbox or container under an unprivileged account with a read-only, minimal filesystem. 7. If local assets are necessary, copy validated assets into an isolated directory and restrict renderer access to that directory rather than the host filesystem. 8. Apply CPU, memory, execution-time, and output-size limits to the rendering process. 9. Keep the rendering engine patched and consider migrating from the archived or insufficiently maintained `wkhtmltopdf` stack to a maintained renderer with stronger sandboxing controls. ]]>
