T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/facts_sql.sh:8
- Finding
- Executable Shell Configuration Enables Command Execution<![CDATA[ ## Vulnerability Details **File Location**: `scripts/facts_sql.sh:8-16`, `scripts/state_kv.sh:19-24`, `scripts/qdrant_request.sh:11-16` **Vulnerability Type**: Executable configuration file / shell command injection **Risk Level**: High ### Vulnerable Code `scripts/facts_sql.sh:8-16`: ```bash ENV_FILE="${MEMORY_STACK_ENV:-$STACK_ROOT/.env}" if [[ ! -f "$ENV_FILE" ]]; then echo "[facts_sql] Missing env file: $ENV_FILE" >&2 exit 1 fi set -a # shellcheck disable=SC1090 source "$ENV_FILE" ``` `scripts/state_kv.sh:19-24`: ```bash ENV_FILE="${MEMORY_STACK_ENV:-$STACK_ROOT/.env}" if [[ -f "$ENV_FILE" ]]; then set -a # shellcheck disable=SC1090 source "$ENV_FILE" ``` `scripts/qdrant_request.sh:11-16`: ```bash ENV_FILE="${MEMORY_STACK_ENV:-$STACK_ROOT/.env}" if [[ -f "$ENV_FILE" ]]; then set -a # shellcheck disable=SC1090 source "$ENV_FILE" ``` ### Technical Analysis All three scripts load the stack configuration by using Bash's `source` command. An environment file sourced this way is executable shell code, not merely a collection of configuration values. It may contain command substitutions, function calls, redirections, or arbitrary commands. The `MEMORY_STACK_ENV` variable also permits callers to select a different file. Therefore, exploitation is possible if an attacker can modify the default `.env`, influence `MEMORY_STACK_ENV`, or otherwise cause a malicious file to be selected. Loading connection configuration is necessary for the Skill's declared functionality, but executing that configuration as shell code exceeds the minimum privilege required. The vulnerability is not evidence that the included `.env` is currently malicious. It creates a command-execution boundary that depends entirely on the integrity of an external file. ### Attack Path 1. An attacker obtains write access to the default memory-stack `.env`, or influences the environment used to launch the helper and sets `MEMORY_STACK_ENV` to an attacker-controlled ...[truncated 850 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not use `source` to parse a credential or configuration file. - Parse only an explicit allowlist of required `KEY=VALUE` entries and reject command substitutions, shell operators, malformed names, duplicate keys, and unexpected fields. - Use a structured configuration format and a parser that does not evaluate shell syntax where practical. - Resolve the selected configuration path to a canonical path and restrict it to an approved directory. - Reject configuration files with unexpected ownership or permissions. Secret-bearing files should normally be owned by the service account and readable only by that account. - If `MEMORY_STACK_ENV` must remain supported, treat it as a privileged configuration option and validate the target before opening it. - Apply the same hardened loader consistently to all three scripts. ]]>
