T09 · Insecure Skill Coding Practices
- Location
scripts/auth.py:62- Finding
API Key Stored Without Enforced Owner-Only File Permissions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/auth.py:62-73
Vulnerability Type: Insecure plaintext credential storage permissions
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 creation 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 Skill stores the API key in plaintext at
~/.upkuajing/.envbut does not explicitly enforce owner-only permissions on either the directory or the credential file. The effective permissions therefore depend on the user's current umask and any permissions already assigned to an existing file.If the file already exists with permissive permissions, opening it with mode
wtruncates and rewrites it without correcting those permissions. On a multi-user system, another local account or process may consequently be able to read the Bearer credential.Reading this specific credential is necessary for authenticated domain-validation requests and does not, by itself, exceed the minimum privilege required by the declared functionality. The vulnerability concerns how that necessary credential is stored.
Attack Path
- A user invokes the API-key creation function.
- The Skill creates or overwrites
~/.upkuajing/.env. - A permissive umask or pre-existing permissive file mode leaves the credential readable by unintended local users or processes.
- A local attacker reads
UPKUAJING_API_KEYfrom the file. - The attacker submits authenticated requests to the provider using the stolen Bearer credential.
This path requires local filesystem access under permissions that allow the attacker to read the file.
Impact Assessment
A ...[truncated 460 chars]
- Remediation
View remediation
Remediation Suggestions
- Create
~/.upkuajingwith owner-only permissions, such as mode0700. - Create the credential file atomically with mode
0600, rather than relying on the process umask. - If the file already exists, verify and correct its permissions before writing.
- Reject symbolic links and other unexpected file types before overwriting the credential path.
- Use an atomic temporary-file-and-rename procedure to avoid partial writes.
- Prefer an operating-system credential manager or secret store where available.
- Avoid displaying any portion of an existing key in status messages.
- Document the required ownership and permissions and warn the user if they cannot be enforced.
- Create
