T09 · Insecure Skill Coding Practices
- Location
SKILL.md:95- Finding
Shell Command Injection Through Unquoted User-Controlled Skill Path
- Content
View full analysis
/dev/null); do python3 -m py_compile "$f" 2>&1 && echo "OK: $f" || echo "SYNTAX ERR: $f" done ``` ### Technical Analysis The Skill explicitly accepts a relative or absolute Skill path from the user and instructs the Agent to interpolate that value directly into shell commands. The `{skill-path}` placeholder is not quoted, canonicalized, or passed as a discrete command argument. If the Agent executes these templates through a shell, metacharacters embedded in the path can be parsed as shell syntax rather than as part of a pathname. Whitespace, wildcards, leading option characters, command separators, redirections, and command substitutions can therefore alter the intended command. The `for f in $(find ...)` form introduces an additional pathname-handling flaw: command substitution and shell word splitting corrupt filenames containing spaces or newlines. An adversarial filename can consequently change which paths are passed to the syntax checker. ### Attack Path 1. An attacker supplies an audit target containing shell syntax, such as a path value conceptually shaped like: ```text /tmp/target; attacker_command; # ``` 2. The Agent replaces `{skill-path}` with the supplied string in a documented command: ```bash ls /tmp/target; attacke ...[truncated 1164 chars]- Remediation
View remediation
&2 exit 1 } ``` 2. Enforce the intended audit boundary. If audits must remain inside an approved workspace, verify that the canonical path is a descendant of that directory before reading it. 3. Quote every path expansion and use `--` to terminate command options: ```bash ls -- "$skill_path/" head -20 -- "$skill_path/SKILL.md" ``` 4. Replace unquoted `find` substitutions with quoted paths: ```bash find "$skill_path" -type f \( \ -name '*.py' -o -name '*.sh' -o -name '*.md' -o -name '*.json' \ -o -name '*.yaml' -o -name '*.js' -o -name '*.cjs' \ -o -name '*.mjs' -o -name '*.ts' \ \) ``` 5. Avoid `for f in $(find ...)`. Use null-delimited records so filenames cannot be split or reinterpreted: ```bash find "$skill_path/scripts" -type f -name '*.py' -print0 | while IFS= read -r -d '' f; do if python3 -m py_compile "$f"; then printf 'OK: %s\n' "$f" else printf 'SYNTAX ERR: %s\n' "$f" >&2 fi done ``` 6. Prefer structured filesystem tools that accept a path argument directly instead of generating shell command strings. 7. Reject unexpected control characters and shell metacharacters as defense in depth, but do not use filtering as a substitute for argument-safe execution and correct quoting. ]]>
