T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:32
- Finding
- Shell Command Injection Through an Unsanitized Metric Extraction Pattern## Vulnerability Details **File Location**: `SKILL.md`, lines 32-75 **Vulnerability Type**: Command injection through unsafe shell interpolation **Risk Level**: High ### Vulnerable Code The following is an English rendering of the relevant instructions: ```bash # The run command is supplied as a configuration parameter. <RUN_COMMAND> > run.log 2>&1 # The extraction pattern is inserted inside a shell command. grep "<EXTRACTION_PATTERN>" run.log ``` ### Technical Analysis The skill accepts a user-provided experiment command and metric extraction pattern, then interpolates those values into shell command strings. In particular, placing the extraction pattern between double quotes does not make it safe when the complete command is subsequently interpreted by a shell. An attacker can include a closing quote followed by shell control operators in the extraction pattern. This terminates the intended `grep` argument and appends an arbitrary command. The skill provides no validation, escaping, argument-array execution, or explicit approval of the fully resolved command. The experiment command is intentionally capable of executing shell operations, but the instructions do not establish command allowlists, repository boundaries, or other containment. The metric pattern creates an additional execution path where data presented as a search expression can become executable shell syntax. ### Attack Path 1. An attacker or untrusted task supplies a malicious metric extraction pattern resembling: ```text " run.log; arbitrary-command; # ``` 2. The agent substitutes the value into the documented command: ```bash grep "" run.log; arbitrary-command; #" run.log ``` 3. The shell interprets the semicolon as a command separator. 4. `arbitrary-command` executes with the same operating-system identity and permissions as the agent. 5. Because evaluation occurs in an autonomous loop, the i ...[truncated 696 chars]
- Remediation
- ## Remediation Suggestions 1. Do not construct the `grep` operation through shell-string interpolation. Invoke the executable with a structured argument array, equivalent to: ```text ["grep", "--", extraction_pattern, "run.log"] ``` 2. If only simple prefixes or metric names are required, validate patterns against a restrictive allowlist rather than accepting arbitrary regular expressions. 3. If a shell is unavoidable, pass user-controlled values as positional parameters instead of embedding them in command text. 4. Reject unexpected control characters, command substitutions, newlines, and shell metacharacters. 5. Display the exact resolved experiment command and obtain explicit approval before its first execution. 6. Run experiments in a sandbox with restricted filesystem access, no unnecessary credentials, limited network access, and bounded process privileges. 7. Add tests using quotes, semicolons, command substitutions, newlines, and option-like patterns to verify that every pattern remains a literal argument.
