T09 · Insecure Skill Coding Practices
- Location
run.sh:6- Finding
Arbitrary Shell Code Execution Through Dot-Sourced Environment File
- Content
View full analysis
Vulnerability Details
File Location:
run.sh:6-10
Vulnerability Type: Executable configuration file / shell command execution
Risk Level: Highsh # 读取 .env if [ -f "$DIR/.env" ]; then set -a . "$DIR/.env" set +a fiTechnical Analysis
The script loads
.envwith the Bash dot command (. "$DIR/.env"). Dot-sourcing executes the file as shell code rather than parsing it strictly as key-value configuration. Consequently, shell commands, command substitutions, redirections, functions, and other executable syntax placed in.envrun with the privileges of the user or Agent invokingrun.sh.The quoted path prevents path-splitting issues but does not prevent execution of malicious content within the file.
Attack Path
- An attacker gains the ability to create or modify
.envin the project directory, such as through an untrusted archive, shared workspace, compromised repository artifact, or another local write primitive. - The attacker adds shell syntax to
.env, for example a command substitution or standalone command alongside an apparently legitimateWEBHOOK_URLassignment. - A user or Agent invokes
run.sh. - Bash dot-sources
.envand executes the attacker-controlled shell instructions beforediscord_send.shis called. - The injected commands run with all filesystem, network, and process privileges available to the invoking account.
Impact Assessment
Successful exploitation provides arbitrary command execution under the invoking user's security context. The attacker could read or modify accessible files, access environment secrets, initiate network connections, or alter project data. This code does not itself elevate privileges, so the scope is limited to permissions already held by the invoking account.
- An attacker gains the ability to create or modify
- Remediation
View remediation
Remediation Suggestions
Do not execute
.envas shell code. Replace dot-sourcing with a strict configuration parser that:- Permits only an explicit allowlist of keys, such as
WEBHOOK_URL. - Accepts only a well-defined
KEY=VALUEgrammar. - Rejects command substitutions, shell operators, redirections, function declarations, and unexpected keys.
- Validates each parsed value before exporting it.
- Requires restrictive file ownership and permissions where the threat model includes other local users.
Prefer supplying
WEBHOOK_URLthrough a trusted process environment or a dedicated secret manager. If a configuration file is necessary, use a non-executable format and parse it with a suitable parser.- Permits only an explicit allowlist of keys, such as
