T09 · Insecure Skill Coding Practices
- Location
scripts/auth.py:62- Finding
API credential file is created without explicitly restrictive permissions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/auth.py:62-73
Vulnerability Type: Insecure storage of authentication credentials
Risk Level: Mediumpython 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) } try: with open(env_file, 'w', encoding='utf-8') as f: f.write(f"{API_KEY_ENV}={api_key}\n")Technical Analysis
The code stores a reusable Bearer API credential in
~/.upkuajing/.env, but creates both the parent directory and credential file using permissions derived solely from the process umask. It does not enforce owner-only permissions such as0700for the directory and0600for the file.On a multi-user system with an unusually permissive umask, the resulting credential file may be readable by other local users. The behavior is functionally necessary because authenticated API operations require the key, and the code only accesses the documented
UPKUAJING_API_KEY; the issue is the security of the persistence mechanism rather than excessive credential scope.Attack Path
- A user runs
python scripts/auth.py --new_key. - The service returns an API key.
- The script creates
~/.upkuajingand writes the key to.envusing process-default permissions. - If the effective permissions permit group or world access, another local account reads the file.
- The attacker uses the stolen Bearer token against the UpKuaJing API.
Impact Assessment
A local attacker who obtains the credential may perform authenticated operations available to that API key. Depending on server-side authorization, this could include consuming paid merchant-search calls, viewing account information, retrieving pricing details, submitting error reports, or creating paymen ...[truncated 214 chars]
- A user runs
- Remediation
View remediation
Remediation Suggestions
- Create
~/.upkuajingwith mode0700. - Create the credential file atomically with mode
0600, for example usingos.openwithO_CREAT | O_WRONLY | O_TRUNCand an explicit mode. - Apply
chmod(0o700)andchmod(0o600)to existing directories and files before trusting them. - Reject symbolic links and verify that the destination is a regular file owned by the current user.
- Use atomic replacement through a securely created temporary file to prevent partial writes.
- Prefer an operating-system credential store when one is available.
- Avoid disclosing even a prefix of an existing API key in user-facing messages.
- Create
