T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/send_email.sh:7
- Finding
- Credential File Is Executed as Arbitrary Shell Code<![CDATA[ ## Vulnerability Details **File Location**: `scripts/send_email.sh`, lines 7–9 **Vulnerability Type**: Unsafe execution of a credential configuration file **Risk Level**: Medium ```bash if [ -z "$MAILGUN_API_KEY" ] && [ -f ~/.config/mailgun/credentials ]; then source ~/.config/mailgun/credentials fi ``` ### Technical Analysis The `source` command executes the entire contents of `~/.config/mailgun/credentials` in the current shell. It does not restrict the file to variable assignments, so any shell command placed in the credential file will run with the permissions of the user invoking the Skill. The script only checks that the path exists as a file. It does not verify: - That the file is owned by the invoking user. - That its permissions prevent modification by other users. - That the path is not a symbolic link. - That the contents contain only approved Mailgun configuration keys. - That the configuration syntax is non-executable. Executing a configuration file exceeds the minimum privileges necessary to retrieve `MAILGUN_API_KEY` and `MAILGUN_DOMAIN`. It is also inconsistent with `SKILL.md`, which primarily documents environment-variable configuration rather than executable credential files. This does not establish that the bundled project is intentionally malicious. Exploitation requires an attacker or compromised process to gain write or redirection influence over the credential path. ### Attack Path 1. An attacker gains the ability to create, replace, modify, or redirect `~/.config/mailgun/credentials`. 2. The attacker inserts arbitrary shell commands into the file, for example commands that copy accessible data or modify user files. 3. The user invokes `scripts/send_email.sh` while `MAILGUN_API_KEY` is unset. 4. The file existence test succeeds. 5. `source ~/.config/mailgun/credentials` executes the attacker-controlled commands in the current shell. 6. The commands run with the invoking user's privileges and access to that user's en ...[truncated 516 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Remove the executable credential-file fallback and require the documented environment variables. If file-based configuration is necessary: 1. Use a non-executable configuration format, such as JSON, and parse it with a parser that never evaluates shell syntax. 2. Allow only explicitly supported keys, such as `MAILGUN_API_KEY`, `MAILGUN_DOMAIN`, `MAILGUN_FROM`, and `MAILGUN_DEFAULT_TO`. 3. Reject symbolic links and non-regular files. 4. Verify that the file is owned by the invoking user. 5. Require restrictive permissions, such as mode `0600`. 6. Store the file under a fixed, user-controlled directory with restrictive permissions. 7. Never use `source`, `.`, `eval`, or command substitution to parse credential data. 8. Update `SKILL.md` so its documented configuration mechanism exactly matches the implementation. ]]>
