T09 · Insecure Skill Coding Practices
- Location
scripts/setup.sh:58- Finding
Configuration Replacement May Weaken Permissions on Stored Credentials
- Content
View full analysis
"${CONFIG_FILE}.tmp" && mv "${CONFIG_FILE}.tmp" "$CONFIG_FILE" # Add rei to model allowlist so switching works jq '.agents.defaults.models["rei/rei-qwen3-coder"] = {"alias": "rei"}' "$CONFIG_FILE" > "${CONFIG_FILE}.tmp" && mv "${CONFIG_FILE}.tmp" "$CONFIG_FILE" ``` ### Technical Analysis The shell creates `${CONFIG_FILE}.tmp` using the process's current `umask`. The script neither explicitly restricts the temporary file to mode `0600` nor preserves the original configuration file's permissions and ownership. Under a common `022` umask, the temporary file may be created with mode `0644`. The temporary file contains the Rei API key and may also contain credentials for other configured providers. The subsequent `mv` makes this newly created file the permanent `clawdbot.json`, potentially replacing a previously restricted configuration with a world-readable file. The temporary path is also predictable. Although the script writes through shell redirection and does not itself run with elevated privileges, a predictable path provides weaker protection against local filesystem interference than a securely created temporary file. ### Attack Path 1. A victim has a Clawdbot configuration containing provider credentials and runs `scripts/setup.sh`. 2. The victim's environment uses a permissive umask, such as `022`. 3. Shell redirection creates `~/.clawdbot/clawdbot.json.tmp` with permissions derived from that umask. 4. `jq` writes the full configuration, including API keys, to the temporary file. 5. `mv` replaces the original configuration with the newly created file without restoring the original restrictive permissions. 6. An ...[truncated 769 chars]- Remediation
View remediation
"$TMP_FILE" jq empty "$TMP_FILE" chmod 600 "$TMP_FILE" mv "$TMP_FILE" "$CONFIG_FILE" trap - EXIT ``` Where portability permits, also preserve the original owner and restrictive mode rather than assuming `0600`. ]]>
