T09 · Insecure Skill Coding Practices
- Location
scripts/auth.py:62- Finding
API Key Stored Without Enforced Restrictive File Permissions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/auth.py, lines 62–73
Vulnerability Type: Plaintext credential storage with permissions inherited from the process umask
Risk Level: MediumVulnerable Code:
python # Ensure ~/.upkuajing directory exists try: UPKUAJING_DIR.mkdir(parents=True, exist_ok=True) except OSError as e: return { "success": False, "message": f"API key application succeeded, but directory creation failed: {str(e)}.", "envFilePath": str(env_file) } # Save to .env file try: with open(env_file, 'w', encoding='utf-8') as f: f.write(f"{API_KEY_ENV}={api_key}\n")Technical Analysis
The API key is written in plaintext to
~/.upkuajing/.env, but the code does not explicitly assign restrictive permissions to either the directory or credential file. The effective permissions therefore depend on the process umask.Under a permissive umask, the file could be readable by other local users. The implementation also opens an existing path without checking whether it is a symbolic link and does not repair insecure permissions on an existing file. Because the API key authorizes account-related and potentially billable operations, credential storage should not rely on ambient process configuration.
Access to this dedicated credential path is functionally justified by the Skill's authenticated API operations and is disclosed in
SKILL.md. The issue is therefore not the credential access itself, but the failure to securely protect the stored secret.Attack Path
- A victim runs
python scripts/auth.py --new_key. - The API returns a new API key.
- The script creates
~/.upkuajingand writes the key to~/.upkuajing/.envusing permissions derived from the current umask. - If those permissions permit access by another local account, that account reads the plaintext key.
- The attacker uses the stolen Bearer token wit ...[truncated 1005 chars]
- A victim runs
- Remediation
View remediation
Remediation Suggestions
- Create
~/.upkuajingwith mode0700and explicitly repair its permissions if it already exists. - Create the credential file atomically with mode
0600, rather than relying on the process umask. - Use flags such as
O_CREAT,O_WRONLY,O_TRUNC, andO_NOFOLLOWwhere supported to prevent following symbolic links. - Verify that the destination is a regular file owned by the current user before replacing an existing file.
- Write the key to a securely created temporary file in the same directory, flush it, and atomically rename it into place.
- Prefer an operating-system credential store or secret manager when available.
- Never include the complete key in logs, exceptions, command output, or diagnostic reports.
- Document the required ownership and permissions and warn users when insecure existing permissions are detected.
- Create
