T09 · Insecure Skill Coding Practices
- Location
SKILL.md:62- Finding
Command Injection Through Unsanitized Model Argument
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 62-68
Vulnerability Type: Shell command injection through unsafe argument interpolation
Risk Level: HighVulnerable Code:
markdown Parse optional arguments: - `--max-iterations N` — max loop iterations (default: 5, per-phase in phased mode) - `--model MODEL` — pass to codex as `-m MODEL` - `--phase N` — execute only this phase (phased mode only) ```bash codex exec --full-auto -s workspace-write [-m MODEL] < /tmp/codex-handoff-{timestamp}.mdtext ### Technical Analysis The Skill instructs the agent to accept a user-provided `--model MODEL` value and insert it into a Bash command as `-m MODEL`. It does not require validation, an allowlist, shell-safe quoting, or separation of command arguments from shell syntax. If the implementation constructs the displayed command as a shell string, shell metacharacters in `MODEL` can be interpreted as command separators, substitutions, or redirections rather than as part of a model identifier. This creates a command-injection boundary between untrusted command arguments and the Bash tool. The command also uses a predictable path under `/tmp`. Although the `{timestamp}` component can reduce collisions, the instructions do not require secure creation with exclusive permissions. This can expose the workflow to temporary-file collision or symbolic-link risks in a shared environment. ### Attack Path 1. An attacker or untrusted user invokes the Skill with a crafted `--model` value containing shell syntax. 2. The Skill parses that value without applying a strict model-name allowlist. 3. The value is interpolated into the documented `codex exec` Bash command. 4. Bash interprets the injected metacharacters as shell syntax. 5. The injected command executes with the same operating-system permissions and environment available to the supervising agent. Exploitation depends on the documented placeholder ...[truncated 884 chars]- Remediation
View remediation
Remediation Suggestions
- Validate
MODELagainst a strict allowlist of supported model identifiers. Reject whitespace, control characters, shell metacharacters, option prefixes, and unexpected path characters. - Do not construct the invocation by concatenating user-controlled values into a shell command string. Pass each argument as a distinct process argument.
- If Bash must be used, construct an argument array and quote every expansion:
bash args=(exec --full-auto -s workspace-write) if [[ -n "$model" ]]; then [[ "$model" =~ ^[A-Za-z0-9._:/-]+$ ]] || { printf 'Invalid model identifier\n' >&2 exit 2 } args+=(-m "$model") fi codex "${args[@]}" < "$prompt_file" - Prevent option injection by rejecting model values beginning with
-or by using an API that unambiguously separates option values. - Create the prompt file securely with
mktemp, restrict its permissions, quote its path, and remove it with a cleanup trap:bash prompt_file="$(mktemp "${TMPDIR:-/tmp}/codex-handoff.XXXXXXXX")" || exit 1 chmod 600 "$prompt_file" trap 'rm -f -- "$prompt_file"' EXIT - Update the Skill instructions to explicitly prohibit direct interpolation of any user-provided option into Bash commands.
- Validate
