T09 · Insecure Skill Coding Practices
- Location
scripts/init_env.py:34- Finding
API key stored without explicitly restrictive filesystem permissions
- Content
View full analysis
None: path.parent.mkdir(parents=True, exist_ok=True) lines = [f'{key}={quote_env_value(env_map[key])}' for key in sorted(env_map.keys())] path.write_text('\n'.join(lines) + '\n', encoding='utf-8') ``` The function is subsequently used to persist the API key: ```python merged['SUDOCODE_BASE_URL'] = base_url or current_base_url write_env_file(ENV_PATH, merged) print(f'已写入环境变量文件: {ENV_PATH}') print('请重新打开会话,或在当前命令前临时 export 后再运行技能脚本。') ``` ### Technical Analysis The initializer writes `SUDOCODE_IMAGE_API_KEY` to `~/.openclaw/.env`, but neither the containing directory nor the resulting file is assigned an explicit restrictive mode. Their effective permissions therefore depend on the user's current umask and any permissions on an existing file. The function reads all entries from the shared environment file into a dictionary and rewrites the entire file. Consequently, weak resulting permissions could expose not only the Sudocode API key but also unrelated credentials previously stored in the same file. The credential persistence itself is disclosed and supports reuse across sessions, but storing it without enforcing owner-only access exceeds the minimum safe implementation required for that functionality. ### Attack Path 1. A user runs `scripts/init_env.py` in an environment with a permissive umask, or with an existing `.env` file that has permissive permissions. 2. The initializer writes the API key and other preserved environment entries to `~/.openclaw/.env`. 3. The resulting file remains readable by another local account or process. 4. That account or process reads the plaintext API key. 5. The stolen key is used to access the remote service under the victim's account and co ...[truncated 445 chars]- Remediation
View remediation
