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, lines 62-74
Vulnerability Type: Insecure local credential storage
Risk Level: MediumVulnerable Code
python # 确保 ~/.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 application stores a Bearer API credential in
~/.upkuajing/.env, but it does not set explicit permissions on either the containing directory or the credential file. The resulting permissions depend on the process umask and any permissions already assigned to~/.upkuajing.On a multi-user system with a permissive umask or an existing broadly accessible directory, another local user may be able to read the credential. Opening the file with ordinary write mode also does not verify or repair the permissions of an existing file.
Credential persistence is necessary for the declared authenticated API functionality, but protection of the stored credential is insufficiently enforced.
Attack Path
- A user runs
python scripts/auth.py --new_key. - The platform returns a new API key.
- The script creates or overwrites
~/.upkuajing/.envusing permissions derived from the runtime environment. - On a system with permissive file permissions, another local account reads the file.
- The attacker uses the key as a Bearer token against authenticated Upkuajing endpoints.
- The attacker may inspect account information, initiate paid API requests, consume the account balance, or create recharge-order requests.
Impact Assessment
Exploitation requires local filesystem access under an ac ...[truncated 508 chars]
- A user runs
- Remediation
View remediation
Remediation Suggestions
- Create
~/.upkuajingwith mode0700and verify the mode even when the directory already exists. - Create the credential file atomically with mode
0600, such as by usingos.openwithO_CREAT,O_WRONLY, and an appropriate replacement strategy. - Apply
chmod(0o600)to an existing credential file before writing, or reject it with a clear error if ownership or permissions are unsafe. - Verify that the directory and file are owned by the current user and are not symbolic links.
- Avoid truncating the existing credential file until the replacement has been securely written and atomically renamed.
- Prefer an operating-system credential store where available.
- Document credential rotation and revocation procedures in case local disclosure is suspected.
- Create
