T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/generate.py:62
- Finding
- API Key Stored Without Enforced Restrictive Permissions on POSIX Systems## Vulnerability Details **File Location**: `scripts/generate.py`, lines 62–68 **Vulnerability Type**: Insecure plaintext credential storage **Risk Level**: Medium ```python CONFIG_DIR.mkdir(parents=True, exist_ok=True) CONFIG_FILE.write_text(api_key) # Windows 下设置文件权限为仅当前用户可读 if sys.platform == "win32": import stat os.chmod(CONFIG_FILE, stat.S_IREAD | stat.S_IWRITE) ``` ### Technical Analysis The `--save-key` function writes the ModelScope API key in plaintext to `~/.modelscope/api_key`. Restrictive permissions are attempted only on Windows. On POSIX systems, the resulting permissions depend on the process umask. With commonly used settings, the file may be created with mode `0644`, allowing other local users to read it. The configuration directory may also be created with mode `0755`. Persisting the credential is not required for image generation and therefore exceeds the minimum credential-handling privileges necessary for the core function. Although this is not covert credential exfiltration, it creates an avoidable local disclosure risk. ### Attack Path 1. A user invokes the script with `--save-key`. 2. The script creates `~/.modelscope/api_key` and writes the token in plaintext. 3. On a POSIX system with a permissive umask, the file remains readable by other local accounts or processes. 4. An attacker with local filesystem access reads the token. 5. The attacker submits authenticated requests to ModelScope using the victim's credential. ### Impact Assessment An attacker could obtain the user's ModelScope API key and exercise the API permissions associated with it. This may allow unauthorized image-generation requests, consumption of account quota, access to resources available to the token, and activity attributed to the victim. This issue does not independently provide operating-system privilege escalation.
- Remediation
- ## Remediation Suggestions - Prefer an operating-system credential manager rather than a plaintext file. - On POSIX systems, create `~/.modelscope` with mode `0700`. - Create the credential file atomically with mode `0600`, rather than relying on the user's umask. - Explicitly verify and correct existing file permissions before reading or writing the credential. - Avoid following symbolic links when creating or replacing the credential file. - Document how users can revoke and rotate a potentially exposed ModelScope token.
