T09 · Insecure Skill Coding Practices
- Location
SKILL.md:45- Finding
Shell Command Injection Through Direct Interpolation of User-Controlled Arguments
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md:45-61
Vulnerability Type: Shell command injection in Skill instructions
Risk Level: HighThe Skill instructs the Agent to place user-controlled prompts, filenames, editing instructions, and input paths directly into shell command templates:
bash node scripts/generate_image.js -p "{prompt}" -f "{filename}" [-s {size}] [-q {quality}] [-o {output_format}] node scripts/generate_image.js -p "{edit_instruction}" -i "{input_path}" -f "{output_filename}" [-s {size}] [-q {quality}] node scripts/generate_image.js -p "融合图1和图2的风格" -i ref1.png ref2.png -f "merged.png" [-s {size}] [-q {quality}] python scripts/generate_image.py -p "{prompt}" -f "{filename}" [-s {size}] [-q {quality}] [-o {output_format}] python scripts/generate_image.py -p "{edit_instruction}" -i "{input_path}" -f "{output_filename}" [-s {size}] [-q {quality}]Technical Analysis
The placeholders in these templates may contain attacker-controlled content. The surrounding double quotes do not provide reliable shell escaping. A value containing a double quote can terminate the intended argument, after which shell separators, command substitutions, redirections, or other metacharacters can be interpreted by the shell.
This issue exists in the Skill execution instructions rather than in the argument parsing inside the JavaScript and Python programs. Both scripts receive arguments through their runtime argument arrays, but that protection is bypassed if the Agent first constructs a command string and sends it to a shell.
The vulnerable values include:
- The image-generation prompt
- The image-editing instruction
- The output filename
- Input image paths
- Optional size, quality, and output-format values if interpolated before validation
Because the Skill also directs the Agent to preserve the user's complete original prompt, an attacker-controlled quote or shell expression can reach the do ...[truncated 1935 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not construct shell command strings by interpolating prompts, filenames, paths, or other user-controlled values.
- Invoke the program through an argument-array API with shell interpretation explicitly disabled. For example:
javascript spawn( "node", [ "scripts/generate_image.js", "-p", prompt, "-f", filename, "-s", size, "-q", quality ], { shell: false } ); - Update
SKILL.mdto explicitly require structured process invocation and prohibit passing dynamically constructed command strings to a shell. - If the execution environment only provides a shell interface, apply platform-specific shell escaping to every dynamic argument and reject values that cannot be represented safely. Argument-array execution remains the preferred solution.
- Validate output filenames and input paths separately:
- Restrict output files to an approved directory.
- Resolve and normalize paths before use.
- Reject unexpected control characters.
- Enforce allowlists for size, quality, and output format before execution.
- Do not accept shell syntax as part of generated command templates. Keep user prompts as opaque argument values from input collection through process invocation.
- Add tests containing quotes, command substitutions, separators, newlines, and redirection characters to verify that each value reaches the script as exactly one argument and never executes as shell syntax.
