T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/md2pdf.sh:39
- Finding
- Unrestricted Local File Access During Markdown Rendering## Vulnerability Details **File Location**: `scripts/md2pdf.sh`, lines 39–43 **Vulnerability Type**: Unrestricted local resource access in an untrusted document renderer **Risk Level**: Medium ### Vulnerable Code ```bash pandoc "$IN" -o "$OUT" \ --pdf-engine=wkhtmltopdf \ --pdf-engine-opt=--enable-local-file-access \ --css "$CSS" ``` ### Technical Analysis The script accepts a caller-supplied Markdown document and optionally a caller-supplied CSS file, then renders that content through `wkhtmltopdf` with `--enable-local-file-access`. This option permits the rendering engine to access local files available to the account running the conversion. Because Markdown may contain embedded HTML and resource references, and custom CSS may contain resource-loading directives, untrusted input can instruct the renderer to request local resources. The permission is enabled globally rather than being limited to the input document, selected stylesheet, or bundled asset directory. The shell arguments are correctly quoted, so this is not shell command injection. The vulnerability instead arises from granting excessive filesystem access to a document renderer processing attacker-controlled content. ### Attack Path 1. An attacker creates a crafted Markdown document or custom stylesheet containing a reference to a sensitive local resource. 2. A user or automated service invokes `scripts/md2pdf.sh` with that attacker-controlled file. 3. The script passes the content to `wkhtmltopdf` with `--enable-local-file-access`. 4. The renderer attempts to read the referenced resource with the filesystem privileges of the invoking process. 5. If the resource type can be rendered or embedded, its data may appear in the generated PDF and become available to the attacker. ### Impact Assessment Successful exploitation may disclose local files readable by the user or service account performing the conversion. The accessible scope is bounded by operating-system filesystem permission ...[truncated 531 chars]
- Remediation
- ## Remediation Suggestions 1. Remove `--enable-local-file-access` when processing untrusted Markdown or CSS. 2. If local stylesheet access is necessary, restrict access to explicitly trusted directories using supported `wkhtmltopdf` allow-list controls such as `--allow`, rather than granting unrestricted local access. 3. Copy approved inputs and bundled styles into an isolated per-job directory and permit access only to that directory. 4. Reject or sanitize raw HTML, local URI schemes, CSS imports, and resource-bearing elements before rendering untrusted content. 5. Do not permit arbitrary custom CSS in security-sensitive deployments, or validate it against a strict allowlist. 6. Run conversion under a dedicated, unprivileged account inside a sandbox or container with: - No mounted credentials or sensitive host paths - A read-only minimal filesystem - A private temporary working directory - Network access disabled unless explicitly required - CPU, memory, execution-time, and output-size limits 7. Keep `pandoc` and `wkhtmltopdf` patched and test the hardened configuration with crafted local-file references to confirm that files outside the approved directory cannot be accessed.
