T09 · Insecure Skill Coding Practices
- Location
SKILL.md:76- Finding
Unsafe Shell Sourcing of Project-Local Environment File
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 76–81
Vulnerability Type: Unsafe configuration loading leading to arbitrary command execution
Risk Level: MediumVulnerable 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' ) ```Technical Analysis
The documented authentication flow executes
.env.localwith the shell dot command:bash . ./.env.localShell sourcing does not treat the file as passive key-value configuration. It evaluates its contents as shell code in the current subshell. Consequently, a malicious or compromised
.env.localcan contain command substitutions, function calls, redirections, or arbitrary commands that execute when the agent follows the documented procedure.The use of
set -aadditionally exports every variable created or modified by.env.localto subsequent child processes. OnlySERVICEGRAPH_API_KEYis required for the API request, so exporting all values from the file exceeds the minimum privileges and data exposure necessary for the Skill's functionality.Attack Path
- An attacker gains the ability to create or modify
.env.localin the working directory, such as through a compromised repository, generated project artifact, or another process with workspace write access. - The attacker inserts executable shell content into the file. For example, the file could run a local command before assigning the expected API key.
- The agent follows the Skill's instructed authentication recipe.
- The shell evaluates
.env.localrather than parsing it as data. - The attacker's commands execute with the same operating-system identity, filesystem access, environment access, and networ ...[truncated 1039 chars]
- An attacker gains the ability to create or modify
- Remediation
View remediation
Remediation Suggestions
- Do not source
.env.localor any project-controlled configuration file as shell code. - Prefer an environment variable injected directly by the execution harness:
bash test -n "${SERVICEGRAPH_API_KEY:-}" || { printf '%s\n' 'SERVICEGRAPH_API_KEY is not configured' >&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
.env.localsupport is essential, parse only an exactSERVICEGRAPH_API_KEYassignment with a dedicated dotenv parser that does not evaluate shell syntax. Reject duplicate keys, malformed input, command substitutions, and unexpected entries. - Pass only
SERVICEGRAPH_API_KEYto the API client rather than enabling automatic export for every variable withset -a. - Resolve and validate the intended configuration path explicitly. Verify appropriate ownership and restrictive permissions before reading it.
- Continue sending the bearer credential only to the declared HTTPS API endpoint, and ensure verbose HTTP tracing or logs do not record the
Authorizationheader.
- Do not source
