T09 · Insecure Skill Coding Practices
Error
- Location
- recognize.py:104
- Finding
- Hardcoded API credential exposed and automatically used as a fallback<![CDATA[ ## Vulnerability Details **File Locations**: - `recognize.py:104-107` - `usage-guide.md:43-47` **Vulnerability Type**: Hardcoded secret and insecure fallback credential **Risk Level**: High ### Vulnerable Code `recognize.py:104-107`: ```python # 3. If there is still no API Key, use the default Bailian Key as a fallback if not config["api_key"]: config["api_key"] = "<REDACTED_EXPOSED_API_KEY>" config["headers"]["Authorization"] = f"Bearer {config['api_key']}" ``` The original source contains a complete credential-shaped value in place of `<REDACTED_EXPOSED_API_KEY>`. It is redacted here to avoid further disclosure. `usage-guide.md:43-47`: ```python api_key = "<REDACTED_EXPOSED_API_KEY>" headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } ``` The same complete credential is present in the original documentation. ### Technical Analysis The project embeds a bearer credential directly in executable source code and duplicates it in public usage documentation. Anyone who obtains the Skill package can retrieve the credential without authentication. The executable does not merely include the credential as an inactive example. `get_model_config()` automatically selects it whenever neither `IMAGE_MODEL_API_KEY` nor a usable credential in `~/.openclaw/openclaw.json` is found. The credential is then placed in the `Authorization` header and sent to the DashScope endpoint. The configuration instructions increase the likelihood of unintended fallback. `README.md:12-17` documents `BAILIAN_API_KEY`, while the implementation reads `IMAGE_MODEL_API_KEY` at `recognize.py:40-41`. A user following the README can therefore believe that a private key has been configured while the application silently uses the embedded shared key instead. Hardcoded credentials violate secret-isolation principles because they cannot be distributed, rotated, audited, or revoked independently of the application package. ### Attack Pat ...[truncated 1606 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Revoke the exposed credential immediately through the provider console. 2. Review provider logs for unauthorized requests, unusual usage, unexpected charges, and quota exhaustion. 3. Remove the credential from: - `recognize.py` - `usage-guide.md` - Previous repository revisions, release archives, package registries, and cached artifacts. 4. Do not provide a fallback credential. Stop with a clear error when no credential is configured: ```python if not config["api_key"]: raise RuntimeError( "No image-model API key configured. Set IMAGE_MODEL_API_KEY " "or configure a supported provider in OpenClaw." ) ``` 5. Use one consistently documented environment variable. Either update the README to use `IMAGE_MODEL_API_KEY` or intentionally support both names with a documented precedence order. 6. Store credentials in environment variables, an operating-system key store, or a dedicated secret manager. 7. Apply provider-side restrictions where supported, including API scope restrictions, spending limits, rate limits, and credential expiration. 8. Add automated secret scanning to source-control and release pipelines. 9. Ensure error messages and logs never print authorization headers or credential values. ]]>
