T09 · Insecure Skill Coding Practices
- Location
SKILL.md:67- Finding
Command Injection Through Unquoted User-Controlled Target Directory
- Content
View full analysis
` from the user's request (explicit path like `myshop-infra/` or current working directory if unspecified). All subsequent `fmt` / `init` / `validate` commands run in this directory. Before writing any `.tf` file, **MUST** create the directory: ```bash mkdir -p ``` All file writes MUST prefix paths with `/` — never write to the current working directory directly, never write to a generic `outputs/` parent. After generation completes, verify the structure: ```bash ls -R ``` ``` The same unquoted value is subsequently used in additional shell commands. `SKILL.md:365-368`: ```bash (cd \ && terraform fmt -recursive \ && terraform init -backend=false \ && terraform validate -json) ``` `SKILL.md:451-453`: ```bash (cd && terraform init && terraform plan -out=tfplan) ``` `references/auth-and-network.md:101-102`: ```bash rm -rf /.terraform /.terraform.lock.hcl (cd && terraform init -backend=false) ``` ### Technical Analysis The workflow explicitly derives `` from the user's request and then places it into shell command templates without requiring shell-safe quoting, argument separation, or input validation. Shell metacharacters in a supplied path—such as semicolons, command substitutions, redirections, pipes, or newlines—can change the structure of the resulting command. For example, direct substitution of a value resembling: ```text infra; attacker-command ``` into: ```bash mkdir -p ``` would produce a shell command equivalent to: ```bash mkdir -p infra; a ...[truncated 2251 chars]- Remediation
View remediation
&& terraform ...`. 4. Replace the cleanup example with quoted, constrained operations: ```bash rm -rf -- "$target_dir/.terraform" rm -f -- "$target_dir/.terraform.lock.hcl" ``` Before cleanup, verify that `target_dir` is non-empty, canonical, and located within the approved workspace. Consider requiring explicit user confirmation before destructive cleanup. 5. Update every occurrence consistently, including the generation, validation, planning, content-grep, and network-recovery commands. Fixing only `mkdir` would leave later injection points exploitable. 6. Add negative tests using paths containing spaces, leading hyphens, semicolons, command substitutions, newlines, wildcard characters, and traversal components. Tests should confirm that each value is handled only as a path and never parsed as shell syntax. ]]>
