T09 · Insecure Skill Coding Practices
- Location
scripts/auth.py:60- Finding
API Key Stored Without Enforced Restrictive File Permissions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/auth.py:60-73
Vulnerability Type: Insecure plaintext credential storage
Risk Level: Mediumpython # 确保 ~/.upkuajing 目录存在 try: UPKUAJING_DIR.mkdir(parents=True, exist_ok=True) except OSError as e: return { "success": False, "message": f"API密钥申请成功,但创建目录失败:{str(e)}。\n请手动创建目录 {UPKUAJING_DIR} 并设置环境变量 {API_KEY_ENV}。", "envFilePath": str(env_file) } # 保存到 .env 文件 try: with open(env_file, 'w', encoding='utf-8') as f: f.write(f"{API_KEY_ENV}={api_key}\n")Technical Analysis
The Skill legitimately requires an API key to authenticate requests, so reading a dedicated key from
UPKUAJING_API_KEYor~/.upkuajing/.envdoes not exceed the minimum functional privilege by itself. However, the key-creation workflow stores the bearer token in a plaintext file without explicitly setting owner-only permissions.Path.mkdir()andopen(..., 'w')rely on the process umask to determine permissions. Under a permissive or misconfigured umask, the directory or file may be readable by other local accounts. The code also does not verify that the destination is owned by the current user or reject a pre-existing symbolic link. Opening the file in write mode truncates its previous contents.Attack Path
- A victim runs
python scripts/auth.py --new_key. - The service returns a new API key.
- The script writes the key to
~/.upkuajing/.envusing permissions derived from the current umask. - On a multi-user system with permissive resulting permissions, another local user reads the file and obtains the bearer token.
- The attacker uses the token against the Upkuajing API to access associated account functions or consume paid services within the privileges assigned to that token.
If an attacker can pre-create or manipulate the destination as a symbolic link, the unchecked write may also overwrite a fil ...[truncated 646 chars]
- A victim runs
- 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, rather than relying on the ambient umask. - Reject symbolic links and unexpected file types before reading or replacing the credential file.
- Write to a securely created temporary file in the same directory, flush it, set its permissions, and atomically replace the destination.
- Preserve unrelated
.enventries instead of truncating the entire file. - Prefer the process environment or an operating-system credential store where available.
- Avoid displaying any portion of the existing key in output, including the prefix currently shown by
scripts/auth.py:33.
- Create
