T09 · Insecure Skill Coding Practices
- Location
scripts/generate.py:62- Finding
API Key Stored Without Enforced Restrictive Permissions on POSIX Systems
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate.py, lines 62–68
Vulnerability Type: Insecure plaintext credential storage
Risk Level: Mediumpython 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-keyfunction 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 mode0644, allowing other local users to read it. The configuration directory may also be created with mode0755.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
- A user invokes the script with
--save-key. - The script creates
~/.modelscope/api_keyand writes the token in plaintext. - On a POSIX system with a permissive umask, the file remains readable by other local accounts or processes.
- An attacker with local filesystem access reads the token.
- 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.
- A user invokes the script with
- Remediation
View remediation
Remediation Suggestions
- Prefer an operating-system credential manager rather than a plaintext file.
- On POSIX systems, create
~/.modelscopewith mode0700. - 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.
