T09 · Insecure Skill Coding Practices
- Location
scripts/auth.py:63- Finding
API Key Stored Without Explicitly Restrictive File Permissions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/auth.py:63-74
Vulnerability Type: Plaintext credential storage with permissions dependent on the process umask
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 stores the bearer API key in plaintext at
~/.upkuajing/.env. Neither the containing directory nor the credential file is explicitly assigned owner-only permissions. Their effective permissions therefore depend on the process umask and any permissions already present on the paths.On a system with a permissive umask, the file may be created as readable by the local group or other users. If the directory or file already exists with permissive permissions,
mkdir(..., exist_ok=True)and opening the file with modewdo not reliably correct those permissions.The file operation also follows symbolic links. If an attacker with relevant local filesystem access can prepare the path before key creation, the absence of symlink checks could cause the key to be written through an attacker-controlled link.
Reading this specific credential is necessary for authenticated Skill functionality, and the audit found that it is sent only as a Bearer header to the fixed HTTPS API origin. The issue is therefore not the credential's legitimate use, but its insufficiently hardened local storage.
Attack Path
- The victim runs
python scripts/auth.py --new_key. - The platform returns a new API key.
- The script creates
~/.upkuajingand writes.envwithout explicitly setting modes `0 ...[truncated 972 chars]
- The victim runs
- Remediation
View remediation
Remediation Suggestions
- Create the credential directory with owner-only permissions:
python UPKUAJING_DIR.mkdir(mode=0o700, parents=True, exist_ok=True) os.chmod(UPKUAJING_DIR, 0o700) - Create the credential file atomically with mode
0600, using flags such asO_CREAT,O_WRONLY,O_TRUNC, andO_NOFOLLOWwhere supported. - Explicitly apply
os.chmod(env_file, 0o600)after creation and verify the resulting ownership and mode. - Reject symbolic links and non-regular files before writing. Use
lstat()or platform-appropriate secure file-opening APIs. - Avoid overwriting unrelated entries in an existing
.envfile. Parse and update only the designated key while preserving other content securely. - Prefer an operating-system credential store or secret manager when available.
- Document key revocation and rotation procedures in case local disclosure is suspected.
- Create the credential directory with owner-only permissions:
