T09 · Insecure Skill Coding Practices
- Location
- scripts/crawl.sh:23
- Finding
- Credential Environment File Is Executed as Arbitrary Shell Code<![CDATA[ ## Vulnerability Details **File Location**: `scripts/crawl.sh:23-27`; `scripts/poll.sh:6-10` **Vulnerability Type**: Unsafe execution of a credential configuration file **Risk Level**: Medium ### Vulnerable Code In `scripts/crawl.sh:23-27`: ```bash # Load credentials if [[ -f ~/.clawdbot/secrets/cloudflare-crawl.env ]]; then source ~/.clawdbot/secrets/cloudflare-crawl.env fi : "${CF_ACCOUNT_ID:?Set CF_ACCOUNT_ID}" : "${CF_CRAWL_API_TOKEN:?Set CF_CRAWL_API_TOKEN}" ``` In `scripts/poll.sh:6-10`: ```bash if [[ -f ~/.clawdbot/secrets/cloudflare-crawl.env ]]; then source ~/.clawdbot/secrets/cloudflare-crawl.env fi : "${CF_ACCOUNT_ID:?Set CF_ACCOUNT_ID}" : "${CF_CRAWL_API_TOKEN:?Set CF_CRAWL_API_TOKEN}" ``` ### Technical Analysis The Bash `source` command does not treat the referenced file as a passive environment-variable file. It parses and executes its entire contents as shell code in the context of the current script. The scripts expect the file to contain only `CF_ACCOUNT_ID` and `CF_CRAWL_API_TOKEN` assignments, but they do not validate its ownership, permissions, syntax, or allowed variable names. Consequently, command substitutions, function definitions, redirections, and arbitrary shell commands placed in the file will execute whenever either script starts. For example, a compromised file could contain an assignment with command substitution: ```bash CF_ACCOUNT_ID="$(attacker_controlled_command)" CF_CRAWL_API_TOKEN="..." ``` Exploitation requires the attacker or another compromised component to obtain the ability to create or modify `~/.clawdbot/secrets/cloudflare-crawl.env`. The use of `source` then turns control over what should be data-only configuration into code execution. ### Attack Path 1. An attacker compromises a provisioning process, backup restoration process, account-level utility, or other component capable of writing the credential file. 2. The attacker adds arbitrary Bash commands or command substitutions to `~/.clawd ...[truncated 933 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not load the credential file with `source`, `.`, or `eval`. - Prefer passing credentials through an established secret manager or a controlled process environment. - If a file must be supported, implement a data-only parser that: - Accepts only `CF_ACCOUNT_ID` and `CF_CRAWL_API_TOKEN`. - Rejects duplicate keys, unknown keys, malformed lines, command substitutions, and shell metacharacters. - Does not evaluate the parsed values as shell syntax. - Verify that the file is owned by the current user and is not a symbolic link. - Require restrictive permissions, such as mode `0600`, before reading it. - Reject values containing unexpected control characters or newlines. - Document that the credential file must never be generated from untrusted input. ]]>
