T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:58
- Finding
- Shell Command Injection Through Unvalidated CLI Configuration<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 58–65; related command construction guidance at lines 169–180 **Vulnerability Type**: Shell command injection **Risk Level**: High ### Vulnerable Code ```text 1. **Use exec tool** to launch the coding agent: ``` exec tool with parameters: - command: "opencode run --model <MODEL> \"$(cat PROMPT.md)\"" - workdir: <project_path> - background: true - pty: true - yieldMs: 60000 - timeout: 3600 ``` The related command templates and optional flags include: ```text | **OpenCode** | `opencode run --model <MODEL> "$(cat PROMPT.md)"` | | **Codex** | `codex exec <FLAGS> "$(cat PROMPT.md)"` (requires git) | | **Claude Code** | `claude <FLAGS> "$(cat PROMPT.md)"` | | **Pi** | `pi --provider <PROVIDER> --model <MODEL> -p "$(cat PROMPT.md)"` | | **Goose** | `goose run "$(cat PROMPT.md)"` | Common flags: - Codex: `--full-auto`, `--yolo`, `--model <model>` - Claude: `--dangerously-skip-permissions` ``` ### Technical Analysis The Skill instructs an agent to collect CLI, model, provider, flag, and working-directory values and interpolate them into a shell command string. It does not require strict allowlisting, shell-safe argument handling, structured executable/argument arrays, or rejection of shell metacharacters. If an attacker can influence a value substituted for `<MODEL>`, `<FLAGS>`, `<PROVIDER>`, or a custom CLI command, shell syntax embedded in that value may terminate or alter the intended command and append an arbitrary command. For example, a value containing command separators or command substitution syntax could be interpreted by the shell when the constructed string is passed to `exec`. The prompt file expansion is enclosed in double quotes, which limits injection directly through the contents of `PROMPT.md`. However, the configuration placeholders outside that quoted expansion remain unsafe when substituted without validation. The documented availability of `- ...[truncated 2005 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Avoid shell command strings** - Invoke tools using a structured executable and argument array. - Pass the prompt as a discrete argument or through standard input rather than using `$(cat PROMPT.md)`. 2. **Strictly allowlist configuration** - Permit only explicitly supported CLI executable names. - Validate model and provider names against known-safe identifiers. - Represent optional flags as enumerated configuration choices rather than arbitrary text. - Reject values containing shell metacharacters, whitespace patterns, redirection operators, command substitutions, or control characters. 3. **Do not accept arbitrary CLI fragments** - Separate the executable, model, provider, and flags into distinct validated fields. - Resolve executables to trusted absolute paths where feasible. - Do not permit users or repository content to supply raw command prefixes or suffixes. 4. **Harden auto-approval behavior** - Disable `--yolo` and `--dangerously-skip-permissions` by default. - Require explicit, informed user confirmation before enabling any auto-approval mode. - Prefer the most restrictive sandbox and permission mode supported by the selected CLI. 5. **Enforce execution isolation** - Run coding agents in a container or equivalent sandbox with a read/write mount limited to the intended repository. - Remove unrelated credentials and sensitive environment variables. - Apply outbound network restrictions unless network access is required. - Run under a dedicated, unprivileged operating-system account. 6. **Validate paths** - Resolve and verify the working directory against an approved project root. - Reject traversal, symlink escapes, and paths outside the authorized workspace. 7. **Update all examples** - Replace unsafe command-string examples in both `SKILL.md` and `README.md`. - Document that configuration originating from users, repositories, prompts, or generated f ...[truncated 40 chars]
