T09 · Insecure Skill Coding Practices
- Location
scripts/setup-thirdparty.sh:85- Finding
Persistent Shell Command Injection Through Third-Party API Key
- Content
View full analysis
/dev/null || true echo "export $ENV_KEY_NAME=\"$KEY\"" >> "$HOME/.bashrc" export "$ENV_KEY_NAME=$KEY" ``` ### Technical Analysis The `KEY` parameter is controlled by the caller and is interpolated directly into a shell command written to `~/.bashrc`. The script does not apply shell escaping or the key-format validation used by the AgentPlan setup scripts. A value containing double quotes, command substitutions, shell metacharacters, or embedded newlines can terminate the intended assignment and append arbitrary commands. Because the resulting content is placed in `.bashrc`, the injected command executes whenever a future interactive Bash shell sources that file. Although the immediate `export "$ENV_KEY_NAME=$KEY"` command safely treats the value as one argument, that does not protect the separately generated `.bashrc` statement. ### Attack Path 1. An attacker persuades a user or agent to configure a third-party provider with a crafted API key. 2. The Skill invokes `setup-thirdparty.sh` with the crafted value. 3. The script writes the unescaped value into `~/.bashrc`. 4. The payload breaks out of the quoted environment assignment and adds a shell command. 5. The command executes when the user opens a new Bash session or manually runs `source ~/.bashrc`. 6. Since the modification is persistent, the payload may execute repeatedly across sessions. ### Impact Assessment Successful exploitation provides arbitrary command execution with the privileges of the user running the Skill. An attacker could read or modify user files, steal other API credentials, alter development tools, install additional persistence, or redirect future model traffic. The scope is the affected user account and all data and se ...[truncated 38 chars]- Remediation
View remediation
> "$HOME/.bashrc" ``` - Validate `ENV_KEY_NAME` independently using: ```bash [[ "$ENV_KEY_NAME" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || exit 1 ``` - Reject credentials containing control characters or line breaks. - Write changes atomically through a securely created temporary file. - Add regression tests using credentials containing quotes, newlines, dollar signs, backticks, and command substitutions. ]]>
