T09 · Insecure Skill Coding Practices
- Location
SKILL.md:13- Finding
Insecure API Key Storage and Unsafe Environment File Parsing
- Content
View full analysis
> ~/.clawdbot/.env ``` ``` ```bash if [ -z "$LLMWHISPERER_API_KEY" ]; then if [ -f ~/.clawdbot/.env ]; then # shellcheck disable=SC2046 export $(grep -v '^#' ~/.clawdbot/.env | grep 'LLMWHISPERER_API_KEY' | xargs) fi fi ``` ### Technical Analysis The documented setup command appends the API key to a plaintext file without explicitly creating the parent directory with restrictive permissions or enforcing mode `0600` on the file. The resulting permissions depend on the existing file mode and the user's `umask`. On a multi-user system, permissive permissions could expose the credential to other local accounts. The loading logic also uses command substitution, unquoted word splitting, and `xargs` to construct arguments to the shell's `export` builtin. It selects every non-comment line containing the substring `LLMWHISPERER_API_KEY`, rather than parsing only an exact assignment for the expected variable. Consequently, a party able to modify `~/.clawdbot/.env` can place additional assignments on a matching line and cause them to be exported into the script's process. This construction does not, by itself, cause shell metacharacters produced by command substitution to be reevaluated as commands. Therefore, direct arbitrary command execution is not established by the reviewed code. Nevertheless, exporting unintended variables can alter the behavior of `curl` or other process components and is unnecessary for obtaining the single credential required by the Skill. Reading the specifically declared API key is necessary for the Skill's cloud API functionality, but importing arbitrary assignments from a shared configuratio ...[truncated 2132 chars]- Remediation
View remediation
"$HOME/.clawdbot/.env" unset api_key ``` 3. Parse and export only the exact expected variable. Do not use `export $(...)` or `xargs`: ```bash if [ -z "${LLMWHISPERER_API_KEY:-}" ] && [ -f "$HOME/.clawdbot/.env" ]; then LLMWHISPERER_API_KEY=$( sed -n 's/^LLMWHISPERER_API_KEY=//p' "$HOME/.clawdbot/.env" | head -n 1 ) export LLMWHISPERER_API_KEY fi ``` 4. Reject malformed, empty, or duplicate assignments and verify that the file is a regular file owned by the current user. Refuse to load it when its permissions allow group or world access. 5. Prefer receiving the key through the calling environment or a platform-provided secret manager so that the Skill does not need to read a general-purpose credential file. 6. Clearly disclose that the supplied document is uploaded to `llmwhisperer-api.us-central.unstract.com`, and advise users not to submit sensitive material unless permitted by their security and privacy requirements. ]]>
