T09 · Insecure Skill Coding Practices
- Location
scripts/md2pdf.sh:39- Finding
Unrestricted Local File Access During Markdown Rendering
- Content
View full analysis
Vulnerability Details
File Location:
scripts/md2pdf.sh, lines 39–43
Vulnerability Type: Unrestricted local resource access in an untrusted document renderer
Risk Level: MediumVulnerable 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
wkhtmltopdfwith--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
- An attacker creates a crafted Markdown document or custom stylesheet containing a reference to a sensitive local resource.
- A user or automated service invokes
scripts/md2pdf.shwith that attacker-controlled file. - The script passes the content to
wkhtmltopdfwith--enable-local-file-access. - The renderer attempts to read the referenced resource with the filesystem privileges of the invoking process.
- 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
View remediation
Remediation Suggestions
- Remove
--enable-local-file-accesswhen processing untrusted Markdown or CSS. - If local stylesheet access is necessary, restrict access to explicitly trusted directories using supported
wkhtmltopdfallow-list controls such as--allow, rather than granting unrestricted local access. - Copy approved inputs and bundled styles into an isolated per-job directory and permit access only to that directory.
- Reject or sanitize raw HTML, local URI schemes, CSS imports, and resource-bearing elements before rendering untrusted content.
- Do not permit arbitrary custom CSS in security-sensitive deployments, or validate it against a strict allowlist.
- 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
- Keep
pandocandwkhtmltopdfpatched and test the hardened configuration with crafted local-file references to confirm that files outside the approved directory cannot be accessed.
- Remove
