T09 · Insecure Skill Coding Practices
- Location
SKILL.md:86- Finding
Shell Command Injection Through Unquoted Directory Placeholders
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 86-95 and 135-141
Vulnerability Type: Shell command injection caused by unsafe path interpolation
Risk Level: MediumVulnerable Code
bash # Lines 86-95 ls -la [target_directory] find [target_directory] -type f -exec file {} \; | head -20 du -sh [target_directory]/* | sort -rh | head -20 find [target_directory] -type f | sed 's/.*\.//' | sort | uniq -c | sort -rnbash # Lines 135-141 find [directory] -type f -exec md5 {} \; | sort | uniq -d find [directory] -type f -printf '%f\n' | sort | uniq -d find [directory] -type f -printf '%s %p\n' | sort -nTechnical Analysis
The skill instructs an agent to replace
[target_directory]and[directory]with a user-selected path and execute the resulting shell commands. These placeholders are not quoted and are not separated from shell interpretation through a structured process-execution API.If an agent performs direct textual substitution, shell metacharacters in the supplied value can change the intended command. Characters such as semicolons, command substitutions, redirection operators, pipes, whitespace, and glob metacharacters may be interpreted by the shell rather than treated as part of a filesystem path.
For example, unsafe interpolation of a value conceptually equivalent to:
text /tmp/files; attacker_commandcould transform the first template into two shell commands. A path containing spaces can also split into multiple arguments, while wildcard characters may expand beyond the intended target. The risk arises from the command construction pattern; exploitation depends on an agent substituting untrusted input directly and executing the result through a shell.
Attack Path
- An attacker supplies a crafted directory value or persuades the user to request organization of a directory represented by shell metacharacters.
- The agent substitutes that value directly for
[target_directory]or `[di ...[truncated 983 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not construct shell command strings by directly substituting user-provided paths.
- Prefer a process-execution API that passes the executable and each argument separately without invoking a shell.
- Resolve the requested directory to a canonical absolute path and verify that it exists, is a directory, and remains within the user-approved scope.
- When shell use is unavoidable, assign the validated path to a variable and quote every expansion:
bash target_directory='/validated/absolute/path' ls -la -- "$target_directory" find "$target_directory" -type f -exec file -- {} \; find "$target_directory" -type f -printf '%f\n' find "$target_directory" -type f -printf '%s %p\n'- Avoid concatenating wildcard syntax with untrusted input. For size analysis, use
findor another structured traversal mechanism instead of relying on shell glob expansion. - Reject values containing control characters and never treat a user-provided directory as executable shell syntax.
- Revalidate that every source and destination path remains under the approved root before later move, rename, or deletion operations.
- Retain the existing approval requirement for destructive changes, but do not rely on confirmation as a substitute for safe command construction.
