T09 · Insecure Skill Coding Practices
- Location
SKILL.md:80- Finding
Arbitrary Command Execution Through Unsafe .env.local Sourcing
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 80–86
Vulnerability Type: Unsafe execution of a local environment file
Risk Level: HighVulnerable Code
bash 1. **Just try the call** 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 Skill instructs the agent to load
.env.localusing the POSIX shell.command. This does not treat the file as passive configuration; it evaluates its entire contents as shell code.Because
.env.localis located relative to the current working directory, any party able to create or modify that file can insert shell commands. Those commands execute before the ServiceGraph request and with the same operating-system identity and permissions as the agent's shell. The subshell limits environment changes after completion but does not restrict filesystem access, network access, process creation, or command execution inside it.The ServiceGraph operation only needs access to one environment variable. Executing an entire local file therefore exceeds the minimum privilege necessary for authentication.
Attack Path
- An attacker gains influence over the project workspace or supplies a project containing a crafted
.env.local. - The file contains an apparently valid assignment and an additional command, for example:
bash SERVICEGRAPH_API_KEY=vk_example malicious_command - A user invokes the Skill without independently inspecting
.env.local. - The agent follows the documented authentication procedure:
bash . ./.env.local - The shell evaluates every statement in the file, including
malicious_command. - The injected command runs with the agent process's ...[truncated 921 chars]
- An attacker gains influence over the project workspace or supplies a project containing a crafted
- Remediation
View remediation
Remediation Suggestions
- Remove all instructions that source
.env.localor any other repository-controlled configuration file. - Prefer the documented ServiceGraph MCP/OAuth integration so credentials remain in the harness credential sandbox and do not enter model or shell context.
- For REST usage, require
SERVICEGRAPH_API_KEYto be exported by a trusted user or injected through the execution environment: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 file-based configuration is unavoidable, use a non-evaluating parser that accepts only an exact
SERVICEGRAPH_API_KEYrecord and validates the expected token format. Do not usesource,.,eval, command substitution, or interpolation of arbitrary file contents. - Store credential files outside attacker-controlled repositories, restrict their filesystem permissions, and reject symbolic links or files with unexpected ownership.
- Run network clients in a least-privileged sandbox with narrowly scoped filesystem access and an outbound allowlist limited to
api.servicegraph.co. - Continue instructing users not to paste API keys into chat, and ensure logs do not record authorization headers.
- Remove all instructions that source
