T09 · Insecure Skill Coding Practices
- Location
- scripts/config.py:204
- Finding
- Credential files are created without enforced restrictive permissions<![CDATA[ ## Vulnerability Details **File Location**: `scripts/config.py:204-212` **Vulnerability Type**: Plaintext credential storage with unsafe default permissions **Risk Level**: Medium ### Vulnerable Code ```python # 创建目录 os.makedirs(save_dir, exist_ok=True) # 保存配置 with open(save_path, 'w', encoding='utf-8') as f: json.dump(self._config_data, f, indent=2, ensure_ascii=False) self.config_path = save_path return save_path ``` The configuration object written by this code can contain the Gitee API key, Tencent Cloud SecretId, and Tencent Cloud SecretKey collected elsewhere in the same module. ### Technical Analysis The configuration is persisted as plaintext JSON. Neither the configuration directory nor the file is explicitly assigned owner-only permissions. Consequently, effective permissions depend on the process umask, pre-existing directory permissions, and platform defaults. The same insecure write pattern also occurs when an existing configuration is updated at `scripts/config.py:248-249`: ```python with open(self.config_path, 'w', encoding='utf-8') as f: json.dump(self._config_data, f, indent=2, ensure_ascii=False) ``` Because the configuration may contain long-lived cloud credentials, relying on ambient filesystem defaults does not provide sufficient protection. Existing files with overly broad permissions are not repaired. ### Attack Path 1. A user completes interactive setup and supplies a Gitee API key or Tencent Cloud credentials. 2. The Skill serializes those credentials into `config.json`. 3. The file is created or updated without an explicit owner-only mode. 4. On a system with a permissive umask, shared home directory, insecure backup, or pre-existing broadly readable file, another local account or process reads the configuration. 5. The attacker reuses the exposed credentials against Gitee AI or Tencent Cloud. ### Impact Assessment An attacker may obtain the same remote permissions granted to the exposed credentials. A s ...[truncated 375 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Create the credential directory with owner-only permissions: ```python os.makedirs(save_dir, mode=0o700, exist_ok=True) os.chmod(save_dir, 0o700) ``` 2. Create configuration files atomically with mode `0600`, for example by using `os.open()` with `O_CREAT | O_EXCL` and an explicit mode. 3. Write to an owner-only temporary file, flush and synchronize it, then atomically replace the destination with `os.replace()`. 4. Explicitly repair permissions on existing configuration files with `os.chmod(path, 0o600)` where supported. 5. Prefer an operating-system credential store or dedicated secret manager rather than plaintext JSON. 6. Recommend temporary, narrowly scoped Tencent Cloud credentials restricted to the required bucket and object operations. 7. Avoid storing credentials when suitable environment variables are already available. ]]>
