T09 · Insecure Skill Coding Practices
- Location
pdf-ocr-minimax.js:26- Finding
Shell Command Injection Through User-Controlled File Paths
- Content
View full analysis
Vulnerability Details
File Location:
pdf-ocr-minimax.js:26-32
Vulnerability Type: OS command injection caused by unnecessary shell invocation
Risk Level: HighVulnerable Code
javascript return new Promise((resolve, reject) => { const proc = spawn('pdftoppm', [ '-png', '-r', '200', '-singlefile', pdfPath, path.join(imageDir, 'page') ], { shell: true });Technical Analysis
The
pdfPathvalue originates from the first command-line argument, whileimageDiris derived from the user-selected output directory and the input filename. These values are passed tochild_process.spawn()withshell: true.Enabling shell processing is unnecessary for invoking the fixed
pdftoppmexecutable. It can cause shell metacharacters contained in a valid input filename or output directory to be interpreted as command syntax rather than literal path characters. The earlierfs.existsSync(pdfPath)check does not prevent exploitation because Unix-like filesystems permit shell metacharacters in filenames.Consequently, a maliciously crafted path can cross the intended data boundary and become executable shell syntax.
Attack Path
- An attacker creates or supplies a PDF whose filename contains shell metacharacters and an injected command.
- The attacker persuades the user or Agent to process that file, or otherwise controls the input or output path passed to the CLI.
- The file existence check succeeds because the maliciously named file exists.
pdfToImages()passes the attacker-influenced path tospawn()withshell: true.- The shell interprets the embedded syntax and executes the injected command in addition to, or instead of, the intended
pdftoppmoperation.
Impact Assessment
Successful exploitation permits arbitrary command execution with the privileges of the user or Agent running the Skill. Depending on those privileges, an attacker could r ...[truncated 334 chars]
- Remediation
View remediation
Remediation Suggestions
-
Remove
shell: trueand invokepdftoppmdirectly:javascript const proc = spawn('pdftoppm', [ '-png', '-r', '200', '-singlefile', pdfPath, path.join(imageDir, 'page') ], { shell: false, stdio: ['ignore', 'pipe', 'pipe'] }); -
Resolve and validate input and output paths before use.
-
Verify that the input is a regular file and enforce the expected PDF file type.
-
Reject unexpected conversion exit codes rather than resolving regardless of process failure.
-
Capture and safely report
stderrwithout incorporating it into another command. -
Run the Skill under a minimally privileged account with access limited to the required input and output locations.
-
