T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/cron-trigger.sh:41
- Finding
- Arbitrary Shell Code Execution Through Unsafe .env Sourcing<![CDATA[ ## Vulnerability Details **File Location**: `scripts/cron-trigger.sh`, lines 41-57 **Vulnerability Type**: Execution of configuration data as shell code **Risk Level**: High ### Vulnerable Code ```bash # --- Load .env --- ENV_CANDIDATES=( "$HOME/.openclaw/workspace/.env" "$SKILL_ROOT/.env" "$HOME/.env" ) ENV_LOADED="" for candidate in "${ENV_CANDIDATES[@]}"; do if [[ -f "$candidate" ]]; then set -a source "$candidate" set +a ENV_LOADED="$candidate" break fi done ``` ### Technical Analysis The script uses Bash `source` to load the first available `.env` file. A `.env` file is expected to contain key-value data, but `source` interprets the entire file as executable shell syntax. Consequently, command substitutions, function calls, redirections, and arbitrary shell commands placed in any candidate file are executed with the privileges of the user running the cron job. The broad fallback to `$HOME/.env` is particularly risky because that generic file may not be dedicated to this Skill. This behavior is unnecessary for loading two API keys. A data-only parser would provide the required functionality without executing the file. ### Attack Path 1. An attacker obtains write access to one of the searched files, such as the Skill-local `.env`, through another compromised process, insecure extraction, shared installation, or improper file permissions. 2. The attacker adds shell syntax to the file, for example: ```bash TAVILY_API_KEY=placeholder id > /tmp/news-digest-executed ``` 3. The user installs the documented cron entry. 4. At the next scheduled run, `cron-trigger.sh` sources the file. 5. The injected command executes before configuration validation or the `openclaw` invocation. ### Impact Assessment Successful exploitation provides arbitrary command execution as the account owning the cron entry. The attacker could read that account's files and environment variables, steal Tavily or Xpoz credentials, al ...[truncated 232 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not use `source`, `.`, or `eval` to parse environment files. - Prefer configuring the required variables directly in the cron environment or through a dedicated OpenClaw secret store. - If `.env` support is retained, implement a strict data-only parser that: - Accepts only an allowlist such as `TAVILY_API_KEY`, `XPOZ_API_KEY`, and `NEWS_DIGEST_DATA_DIR`. - Accepts only well-formed `NAME=value` records. - Rejects command substitutions, backticks, shell metacharacters, function definitions, and unexpected variable names. - Remove the generic `$HOME/.env` fallback and use a Skill-specific credential file. - Verify that credential files are regular files, are owned by the invoking user, are not symbolic links, and are not group/world writable. - Recommend permissions such as `chmod 600` for the credential file. ]]>
