T09 · Insecure Skill Coding Practices
- Location
scripts/claude-spawn.sh:159- Finding
Shell Command Injection Through Unescaped tmux Command Construction
- Content
View full analysis
> $LOG_FILE" ``` ### Technical Analysis The script builds command strings by directly interpolating variables into arguments that tmux subsequently executes through a shell. The affected values include: - `WORKDIR`, supplied as a positional command-line argument. - `MODEL`, supplied through `--model`. - `LOG_FILE`, derived from the environment-controlled `CC_HOME`. - `WRAPPER_FILE` and `PROMPT_FILE`, also derived from `CC_HOME`. Quoting the complete command string in the outer shell does not protect the interpolated values when tmux later passes that string to another shell. Spaces and shell metacharacters inside these values are therefore interpreted during this second parsing stage. The validation of `WORKDIR` only verifies that the supplied value names an existing directory. A directory name may legally contain spaces, semicolons, command substitutions, or other shell metacharacters. No restrictive validation is applied to `MODEL` or `CC_HOME`. The `pipe-pane` command has the same issue because `LOG_FILE` is inserted into the shell command `cat >> $LOG_FILE` without shell-safe quoting. ### Attack Path 1. An attacker who can invoke the skill creates an existing directory whos ...[truncated 1284 chars]- Remediation
View remediation
> %q' "$LOG_FILE" tmux pipe-pane -t "$TMUX_SESSION" "$PIPE_COMMAND" ``` 4. Prefer passing data through a controlled wrapper or environment variables rather than embedding it in a shell command. 5. Validate `MODEL` against an explicit allowlist of supported model identifiers. 6. Canonicalize and validate `CC_HOME` and `WORKDIR`, rejecting unexpected control characters. 7. Add regression tests using paths and model values containing spaces, quotes, semicolons, dollar signs, command substitutions, and newlines. ]]>
