T09 · Insecure Skill Coding Practices
- Location
SKILL.md:70- Finding
Unsafe Shell Execution Through Sourcing of .env.local
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 70–75
Vulnerability Type: Unsafe execution of environment configuration as shell code
Risk Level: HighVulnerable Code
bash 1. **Try the call first** through a shell wrapper that sources `.env.local`: ```bash ( set -a; [ -f .env.local ] && . ./.env.local; set +a; curl -sS -H "Authorization: Bearer $SERVICEGRAPH_API_KEY" \ 'https://api.servicegraph.co/v1/datasets/pro_services/fields' )text ### Technical Analysis The shell dot command (`. ./.env.local`) does not treat `.env.local` as a passive environment-variable file. It evaluates the file as shell source code in the current shell. Consequently, command substitutions, shell functions, redirections, and arbitrary commands placed in that file execute when the documented authentication procedure is followed. The use of `set -a` additionally exports every subsequently assigned shell variable to child processes. This exceeds the minimum privilege necessary because the API request requires only `SERVICEGRAPH_API_KEY`. Although the documented `curl` request legitimately sends that key to the declared ServiceGraph HTTPS endpoint, executing the entire environment file is unnecessary for that functionality. ### Attack Path 1. An attacker, compromised development tool, or untrusted project component creates or modifies `.env.local`. 2. The attacker inserts executable shell syntax, such as a command substitution or a standalone command, alongside apparently legitimate environment assignments. 3. A user invokes the Skill to search for or enrich CPA firms. 4. The Agent follows the authentication recipe and runs the supplied shell wrapper. 5. The dot command evaluates the malicious contents before `curl` makes the legitimate API request. 6. The injected commands execute with the operating-system permissions of the Agent process and can access any files, credentials, and network destinations available to that user. ...[truncated 617 chars]- Remediation
View remediation
Remediation Suggestions
- Do not source
.env.localor any dotenv-style configuration file as shell code. - Prefer the documented sandboxed MCP/OAuth flow so the bearer token remains isolated from the Agent context.
- For REST usage, require
SERVICEGRAPH_API_KEYto be supplied through an already-exported process environment:
bash test -n "${SERVICEGRAPH_API_KEY:-}" || { printf '%s\n' 'SERVICEGRAPH_API_KEY is not set' >&2 exit 1 } curl --fail-with-body --silent --show-error \ -H "Authorization: Bearer ${SERVICEGRAPH_API_KEY}" \ 'https://api.servicegraph.co/v1/datasets/pro_services/fields'- If loading a dotenv file is unavoidable, use a strict parser that accepts only the exact
SERVICEGRAPH_API_KEYassignment and rejects command substitution, shell operators, additional variables, multiline values, and executable syntax. - Remove
set -a; pass or export only the single variable required for authentication. - Ensure
.env.localis excluded from version control, readable only by the owning user, and not writable by untrusted project processes. - Continue transmitting the API token only to the fixed
https://api.servicegraph.coorigin over validated HTTPS, without redirects to untrusted hosts.
- Do not source
