T09 · Insecure Skill Coding Practices
- Location
skill.md:58- Finding
API Key Exposure Through Shell History, Terminal Output, and Permissive Initial File Permissions
- Content
View full analysis
Vulnerability Details
File Location:
skill.md, lines 58–68 and 125–126
Vulnerability Type: Insecure credential handling
Risk Level: MediumVulnerable Code
Lines 58–68:
bash mkdir -p ~/.config/preference echo '{"api_key":"pref_agent_xxx"}' > ~/.config/preference/credentials.json chmod 600 ~/.config/preference/credentials.jsonbash export PREFERENCE_API_KEY='pref_agent_xxx'Lines 125–126:
bash echo $PREFERENCE_API_KEY # should show your pref_agent_xxx keyTechnical Analysis
The Skill instructs users to substitute a real bearer token directly into
echoorexportcommands. Interactive shells may retain these commands in shell-history files, despite the surrounding documentation warning users not to expose the key through terminal history, logs, or prompts.The troubleshooting command explicitly prints the complete token to standard output. This can expose it through terminal scrollback, screen sharing, command transcripts, session-recording systems, CI output, or support logs.
The credentials file is also created before
chmod 600is applied. Its initial permissions depend on the user's currentumask. Under a permissive configuration, the file may briefly be readable by other local users or processes. The parent directory is created without an explicit restrictive mode as well.Storing a service credential is necessary for the declared MCP onboarding functionality and does not itself exceed the Skill's required privileges. However, these examples do not apply least-exposure practices when creating and validating that credential.
Attack Path
- A user replaces
pref_agent_xxxwith a real PREF API key and runs the documentedechoorexportcommand. - The command containing the plaintext key is retained in shell history, or the troubleshooting command prints the key into terminal output.
- A local user, process, terminal recorder, log op ...[truncated 1195 chars]
- A user replaces
- Remediation
View remediation
Remediation Suggestions
-
Create the configuration directory with explicit owner-only permissions and set a restrictive
umaskbefore creating the credential file:bash install -d -m 700 ~/.config/preference umask 077 -
Read the key without displaying it or placing it directly in the command line, then serialize it safely:
bash read -rsp "PREF API key: " PREFERENCE_API_KEY printf '\n' jq -n --arg api_key "$PREFERENCE_API_KEY" \ '{api_key:$api_key}' > ~/.config/preference/credentials.json chmod 600 ~/.config/preference/credentials.json unset PREFERENCE_API_KEY -
Prefer an operating-system credential store or secret manager where supported rather than a plaintext JSON file.
-
Remove the instruction to run
echo $PREFERENCE_API_KEY. Validate only whether the variable is populated:bash if test -n "${PREFERENCE_API_KEY:-}"; then echo "PREFERENCE_API_KEY is set" else echo "PREFERENCE_API_KEY is not set" fi -
Warn users who previously followed the examples to inspect and securely clear relevant shell history and logs, then rotate the key if it may have been exposed.
-
Ensure MCP client configurations reference an environment variable or protected credential store rather than embedding the real bearer token in shared configuration files.
-
