T09 · Insecure Skill Coding Practices
Warning
- Location
- references/抓取手册.md:13
- Finding
- Overprivileged API key stored insecurely in a plaintext environment file<![CDATA[ ## Vulnerability Details **File Location**: `references/抓取手册.md`, lines 13 and 28-39 **Vulnerability Type**: Insecure credential handling and excessive API permissions **Risk Level**: Medium ### Vulnerable Code ```bash echo $TIKHUB_API_KEY ``` The registration instructions then direct the user to create a key with all permissions enabled and persist it as follows: ```bash echo 'TIKHUB_API_KEY=YOUR_KEY' >> ~/.env ``` They also provide this alternative: ```bash export TIKHUB_API_KEY=YOUR_KEY ``` ### Technical Analysis The instructions expose the TikHub API key through several unsafe practices: 1. Printing the environment variable can place the secret in terminal output, agent tool output, execution logs, or conversation transcripts. 2. Entering the key directly into a shell command can preserve it in shell history. 3. Appending the key to a generic plaintext `~/.env` file does not ensure restrictive filesystem permissions. 4. Directing the user to enable every API permission violates least privilege. The skill only requires access to the selected social-media platform APIs, not necessarily every capability associated with the account. The project does not contain a hardcoded credential, but it instructs users to handle their own credential in a way that can expose it. ### Attack Path A practical exploitation path requires local, transcript, backup, or log access: 1. The user follows the instructions and executes a command containing the API key. 2. The key is retained in shell history, terminal output, an agent transcript, or the plaintext `~/.env` file. 3. Another local user, compromised process, support operator, transcript reader, or backup recipient obtains access to one of those artifacts. 4. The attacker extracts the TikHub key. 5. The attacker submits requests to TikHub using all permissions granted to the key. 6. Requests consume the victim's paid balance and can access any TikHub functionality authorized by that key. ### Impact Ass ...[truncated 685 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Do not print the credential or ask the agent to inspect its value. Test only whether it exists: ```bash if [ -n "${TIKHUB_API_KEY:-}" ]; then printf '%s\n' 'TikHub API key is configured' else printf '%s\n' 'TikHub API key is not configured' fi ``` 2. Request only the minimum platform-specific permissions needed for the selected workflow. Do not instruct users to select all permissions. 3. Prefer an operating-system credential store or secret manager, such as macOS Keychain, Windows Credential Manager, or a managed secrets service. 4. If a file must be used, create a dedicated credential file with restrictive permissions: ```bash install -m 600 /dev/null "$HOME/.tikhub.env" ``` Populate it through hidden input or a trusted local editor rather than placing the secret directly in the shell command line. 5. Ensure the credential file is excluded from version control, diagnostic bundles, backups where appropriate, and agent-visible artifacts. 6. Document how to revoke and rotate the key after suspected exposure. 7. Redact values matching the key format from command output, logs, error reports, and transcripts. ]]>
