T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/observer-agent.sh:35
- Finding
- Unsafe Shell Execution Through Workspace .env Loading<![CDATA[ ## Vulnerability Details **File Location**: `scripts/setup.sh:50-54`; `scripts/observer-agent.sh:35-39`; `scripts/observer-watcher.sh:29-33`; `scripts/reflector-agent.sh:29-33`; `scripts/backfill-importance.sh:15-18`; `scripts/dream-cycle.sh:10-14` **Vulnerability Type**: Command injection through `eval` and unrestricted shell sourcing **Risk Level**: High ### Vulnerable Code From `scripts/observer-agent.sh`: ```bash # Source env if available (grep-guard: only export KEY=VALUE lines) if [ -f "$WORKSPACE/.env" ]; then set -a # Load provider config + backward compatible OPENROUTER key eval "$(grep -E '^(LLM_BASE_URL|LLM_API_KEY|LLM_MODEL|OPENROUTER_API_KEY)=' "$WORKSPACE/.env" 2>/dev/null)" || true set +a fi ``` The same unsafe `eval` pattern appears in setup, watcher, reflector, and backfill scripts. From `scripts/dream-cycle.sh`: ```bash # Load environment if present if [ -f "$OPENCLAW_WORKSPACE/.env" ]; then set -a # shellcheck disable=SC1090 source "$OPENCLAW_WORKSPACE/.env" set +a fi ``` ### Technical Analysis The scripts treat `.env` as executable shell code rather than as a data file. Restricting the variable names with `grep` does not neutralize shell syntax in the corresponding values. For example, a matching assignment can contain command substitution: ```bash LLM_MODEL=$(malicious-command) ``` When passed to `eval`, the command substitution is executed. Quoting, semicolons, redirections, and other shell constructs can similarly alter execution. The Dream Cycle implementation is broader because it directly sources the entire `.env` file. Any shell statement in that file executes under the account running the scheduled Dream Cycle. This issue is particularly significant because observer and Dream Cycle operations are intended to run through persistent services or scheduled jobs. A malicious `.env` modification can therefore result in delayed and recurring command execution. ### Attack Path 1. An attacker, compromise ...[truncated 956 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Remove every use of `eval` and `source` for dotenv configuration. - Parse `.env` as data using a dedicated parser or a strict Bash routine. - Allow only known variable names. - Require values to conform to field-specific validation rules: - URLs must parse as valid permitted HTTP endpoints. - Model names should use a restricted character set. - API keys should be handled as opaque strings. - Reject command substitutions, backticks, shell operators, redirections, multiline values, and unexpected quoting. - Prefer a permission-restricted configuration file, such as mode `0600`, with a non-shell format such as JSON. - Ensure persistent services use explicitly declared environment values or a validated `EnvironmentFile`, rather than evaluating workspace-controlled shell code. ]]>
