T09 · Insecure Skill Coding Practices
- Location
scripts/auth.py:71- Finding
API Key Exposure Through Documentation and Insufficiently Protected Local Storage
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md:39-41andscripts/auth.py:71-74
Vulnerability Type: Plaintext credential exposure and insecure secret-file creation
Risk Level: MediumVulnerable Code
SKILL.md:39-41:markdown This skill requires an API key. The API key is stored in the `~/.upkuajing/.env` file: ```bash cat ~/.upkuajing/.envtext `scripts/auth.py:71-74`: ```python # 保存到 .env 文件 try: with open(env_file, 'w', encoding='utf-8') as f: f.write(f"{API_KEY_ENV}={api_key}\n")Technical Analysis
Reading
UPKUAJING_API_KEYfrom a dedicated configuration file is necessary for authenticated API requests. However, displaying the entire file withcatis not necessary. Following this instruction exposes the plaintext API key in terminal output, Agent tool output, conversation transcripts, execution logs, or screen recordings.The key file is also created with Python's default file-creation behavior. Its permissions therefore depend on the process
umask; the code does not explicitly ensure owner-only access. On a system with permissive defaults, another local account may be able to read the credential.The implementation does not send the key to an unrelated destination. It is used as a Bearer token for the declared HTTPS API. The vulnerability concerns local disclosure and storage rather than confirmed credential exfiltration by the Skill.
Attack Path
- A user or Agent follows the API-key setup instructions.
- The command
cat ~/.upkuajing/.envprints the complete key. - The key is captured by a tool transcript, shell log, terminal recording, or observer.
- Alternatively,
auth.py --new_keycreates the file under a permissiveumask, allowing another local user to read it. - An attacker uses the exposed key to authenticate to the UpKuaJing API.
Impact Assessment
An attacker obtaining the API key could make authenticated AP ...[truncated 311 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the instruction to run
cat ~/.upkuajing/.env. - Check for the variable without exposing its value, for example by parsing the file and returning only whether the key is present.
- Create
~/.upkuajingwith mode0700. - Create the credential file with mode
0600, usingos.openwith explicit permissions or setting permissions immediately and safely. - Write new credentials atomically through a securely created temporary file in the same directory, then replace the destination.
- Refuse to use a credential file that is owned by another user or is readable by group or other users.
- Prefer the process environment or an operating-system credential store where supported.
- Ensure errors and success messages never include any portion of the key.
- Remove the instruction to run
