T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:20
- Finding
- Shell Command Injection Through Unescaped Template Parameters<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 20–45 **Vulnerability Type**: Shell command injection caused by unsafe interpolation into nested shell commands **Risk Level**: High ### Vulnerable Code ```bash tmux -S ~/.tmux/sock new -d -s <name> "cd <project-dir> && \ PATH=/opt/homebrew/bin:\$PATH codex exec --full-auto '<task description>'; \ EXIT_CODE=\$?; echo 'EXITED:' \$EXIT_CODE; \ openclaw system event --text '<name> finished (exit \$EXIT_CODE) in <project-dir>' --mode now; \ sleep 999999" ``` ```bash tmux -S ~/.tmux/sock new -d -s <name> "cd <project-dir> && \ PATH=/opt/homebrew/bin:\$PATH ralphy --codex --prd PRD.md; \ EXIT_CODE=\$?; echo 'EXITED:' \$EXIT_CODE; \ openclaw system event --text 'Ralph loop <name> finished (exit \$EXIT_CODE) in <project-dir>' --mode now; \ sleep 999999" ``` ```bash tmux -S ~/.tmux/sock new -d -s <name> "cd <project-dir> && \ PATH=/opt/homebrew/bin:\$PATH ralphy --codex --parallel --prd PRD.md; \ EXIT_CODE=\$?; echo 'EXITED:' \$EXIT_CODE; \ openclaw system event --text 'Ralph parallel <name> finished (exit \$EXIT_CODE)' --mode now; \ sleep 999999" ``` ### Technical Analysis The documented templates insert `<name>`, `<project-dir>`, and `<task description>` into a shell command containing multiple nested quoting contexts. No validation or context-aware escaping is prescribed. In the Codex template, the task description appears inside single quotes within a larger double-quoted argument passed to `tmux`. A single quote in the supplied task can terminate the intended Codex argument. Shell metacharacters can then introduce another command. Project directories and session names can similarly affect parsing when they contain whitespace, quotes, command substitutions, separators, or option-like content. Because the shell evaluates this constructed command, escaping must account for every parsing layer. Merely surrounding placeholders with quotes is insufficient. The use of `c ...[truncated 1926 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Replace interpolated shell command strings with a reviewed wrapper script that receives the session name, project directory, and task as distinct positional arguments. 2. Pass commands through argument arrays rather than concatenating shell text. Avoid `eval`, `sh -c`, and equivalent nested parsing wherever possible. 3. If a shell command string is unavoidable, apply context-aware escaping at every shell boundary, such as carefully using `printf '%q'` for Bash-compatible execution. Do not rely on simple surrounding quotes. 4. Restrict session names to a conservative allowlist, such as `^[A-Za-z0-9_-]+$`, and reject option-like or malformed names. 5. Resolve the project directory to a canonical path, verify that it is an approved directory, use `cd -- "$project_dir"`, and reject unexpected control characters. 6. Treat the task description as opaque data. Prefer passing it through a file or a direct argument array rather than embedding it into executable shell syntax. 7. Avoid `--full-auto` as the default. Require explicit user approval and use the least-permissive agent mode suitable for the task. 8. Display the resolved session parameters for confirmation before launching when any value originated from an untrusted source. 9. Add security tests covering single quotes, double quotes, semicolons, command substitutions, newlines, leading hyphens, and whitespace in every substituted field. ]]>
