T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/setup.sh:58
- Finding
- Configuration Replacement May Weaken Permissions on Stored Credentials<![CDATA[ ## Vulnerability Details **File Location**: `scripts/setup.sh`, lines 58–62 **Vulnerability Type**: Unsafe temporary-file creation and failure to preserve sensitive-file permissions **Risk Level**: Medium ### Vulnerable Code ```bash # Add rei provider jq --argjson rei "$REI_PROVIDER" '.models.providers.rei = $rei' "$CONFIG_FILE" > "${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
- <![CDATA[ ## Remediation Suggestions - Preserve the original configuration's ownership and mode when replacing it. - Create temporary files securely with `mktemp` inside the configuration directory. - Set a restrictive umask, such as `umask 077`, before creating files containing credentials. - Explicitly apply mode `0600` to the temporary and final configuration files. - Install cleanup traps so temporary files are removed on interruption or failure. - Validate the completed JSON before atomically replacing the original file. - Avoid a fixed `.tmp` filename. For example: ```bash umask 077 CONFIG_DIR="$(dirname "$CONFIG_FILE")" TMP_FILE="$(mktemp "${CONFIG_DIR}/clawdbot.json.tmp.XXXXXX")" trap 'rm -f "$TMP_FILE"' EXIT jq --argjson rei "$REI_PROVIDER" \ '.models.providers.rei = $rei | .agents.defaults.models["rei/rei-qwen3-coder"] = {"alias": "rei"}' \ "$CONFIG_FILE" > "$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`. ]]>
