T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/alibaba_cloud_model_setup.py:394
- Finding
- Inline API keys are stored without enforcing restrictive file permissions<![CDATA[ ## Vulnerability Details **File Location**: `scripts/alibaba_cloud_model_setup.py:394-408` and `scripts/alibaba_cloud_model_setup.py:447-448` **Vulnerability Type**: Plaintext credential storage with insufficient permission enforcement **Risk Level**: Medium ### Vulnerable Code ```python def save_config(config_path: Path, config: Dict[str, Any]) -> None: """Save config to JSON file with pretty formatting.""" config_path.parent.mkdir(parents=True, exist_ok=True) with open(config_path, "w", encoding="utf-8") as f: json.dump(config, f, indent=2, ensure_ascii=False) f.write("\n") ``` ```python if api_key_source == "inline": provider_config["apiKey"] = api_key # else: apiKey will be read from env var ``` ### Technical Analysis When inline storage is selected, the script inserts the plaintext Alibaba Cloud API key into the OpenClaw JSON configuration. The file is opened using the process's default permission behavior, and the script neither creates it with an explicit owner-only mode nor corrects permissions on an existing file. The resulting permissions depend on the current umask. On systems with permissive defaults, a newly created configuration may be readable by other local users. An existing configuration with weak permissions also remains weak. Timestamped backups can preserve the same sensitive content and inherited permissions. The network transmission of the API key to a fixed Alibaba Cloud HTTPS endpoint is consistent with the declared validation functionality. The vulnerability is the subsequent plaintext storage without enforced filesystem protection. ### Attack Path 1. A user runs the configurator and selects `inline` API-key storage. 2. The script adds the API key to `models.providers.bailian.apiKey`. 3. The script creates or rewrites the configuration without enforcing mode `0600`. 4. The file or a generated backup remains readable under local filesystem permissions. 5. Another local account or comprom ...[truncated 631 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Prefer a supported environment-variable or secret-manager reference instead of embedding the key in JSON. 2. Create new sensitive files atomically with owner-only permissions, such as mode `0600`. 3. Explicitly apply `chmod(0o600)` after replacing an existing configuration and each backup. 4. Verify that the parent directory is not writable or traversable by unauthorized users. 5. Warn users immediately before inline storage and require explicit confirmation. 6. Consider preventing plaintext backup creation when the configuration contains credentials, or secure every backup identically. 7. Add automated tests that assert restrictive permissions for newly created files, existing files, and backups. ]]>
