T09 · Insecure Skill Coding Practices
- Location
scripts/auth.py:67- Finding
API Credential File Is Created Without Explicit Restrictive Permissions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/auth.py, lines 67-74
Vulnerability Type: Insecure local credential storage
Risk Level: Mediumpython # 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)}." } # 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 script stores a bearer API credential in
~/.upkuajing/.env, but it does not explicitly enforce restrictive permissions on either the directory or the file. The effective permissions therefore depend on the process umask and the state of any pre-existing path.On a system with a permissive umask, the file may be readable by other local users. The code also does not verify whether the destination is a symbolic link, whether an existing file is owned by the current user, or whether its permissions are safe before overwriting it.
Reading and storing the dedicated API key is relevant to the skill's authenticated API functionality. The issue is not that the credential is accessed, but that its storage is insufficiently hardened.
Attack Path
- A user invokes
python scripts/auth.py --new_key. - The platform returns a new API key.
- The script creates or overwrites
~/.upkuajing/.envusing permissions inherited from the environment. - On a permissively configured multi-user system, another local user reads the file and extracts
UPKUAJING_API_KEY. - The attacker reuses the bearer key against the UpKuaJing API.
A local attacker who can manipulate the target path may also attempt a symbolic-link attack before file creation, causing the write to target another user-writable file. The practical scope of that variant remains limit ...[truncated 454 chars]
- A user invokes
- Remediation
View remediation
Remediation Suggestions
- Create
~/.upkuajingwith mode0700and verify that it is owned by the current user. - Create the credential file atomically with mode
0600, for example by usingos.openwithO_CREAT | O_EXCL | O_WRONLYand an explicit mode. - If the file already exists, verify its ownership, type, and permissions before opening it.
- Reject symbolic links by using platform-appropriate no-follow options and validating the resolved destination.
- Write through a securely created temporary file in the same directory, flush it, and atomically replace the destination.
- Correct unsafe permissions on existing credential files or fail with a clear warning.
- Prefer a platform credential manager or keyring where available.
- Create
