T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:23
- Finding
- Persistent Plaintext Storage of a User API Key in Source Code## Vulnerability Details **File Location**: `SKILL.md:21-24`, `scripts/generate.py:9-12`, and `scripts/generate.py:198-202` **Vulnerability Type**: Plaintext credential storage and hardcoded secret handling **Risk Level**: High The skill explicitly instructs the agent to request the user's ByteDance image-generation API key and write it directly into the Python source file. The script then reads that persistent source-code value when constructing its authorization header. Relevant instruction from `SKILL.md:21-24`: ```markdown ## 配置 - 先询问使用者的字节跳动生图模型的 API Key 是什么,得到回复后,把它存入 generate.py 的 API_KEY 里面备用 - 如果没有 API Key 或者 API Key 错误,则提示“生图失败,没有正确的 API Key,无法调用生图模型” ``` Credential storage location in `scripts/generate.py:9-12`: ```python # 配置 API_KEY = "" API_URL = "https://ark.cn-beijing.volces.com/api/v3/images/generations" MODEL = "doubao-seedream-4-5-251128" DEFAULT_WORKSPACE = "/root/.openclaw/workspace" ``` Credential use in `scripts/generate.py:198-202`: ```python headers = { "Content-Type": "application/json", "Authorization": "Bearer " + API_KEY } ``` ### Technical Analysis API credentials are secrets and should not be persisted in application source code. Following the documented workflow changes `API_KEY = ""` into a plaintext credential embedded in `scripts/generate.py`. This creates several exposure channels: - The secret can be read by any user or process with access to the project files. - It may be included in source-control commits, patches, backups, archives, audit artifacts, or skill redistribution packages. - Source-code inspection and diagnostic collection can disclose the credential even though the authorization header itself is not printed. - A copied or republished skill package may unintentionally distribute the user's live credential. - The key remains on disk after execution and may outlive the session for which it was provided. The source currently cont ...[truncated 1687 chars]
- Remediation
- ## Remediation Suggestions 1. Remove the instruction to edit `scripts/generate.py` and never persist user credentials in skill source files. 2. Load the key from a dedicated environment variable: ```python API_KEY = os.environ.get("VOLCENGINE_API_KEY") if not API_KEY: raise RuntimeError( "VOLCENGINE_API_KEY is not configured; image generation cannot continue." ) ``` 3. Update the usage documentation to pass the secret through the execution environment rather than modifying source: ```bash read -s VOLCENGINE_API_KEY export VOLCENGINE_API_KEY python3 scripts/generate.py unset VOLCENGINE_API_KEY ``` 4. Prefer an operating-system credential store or managed secret service where available. Grant the runtime access only to the specific secret it needs. 5. Ensure environment variables, secret files, request headers, and exception diagnostics are excluded from logs and generated output. 6. Scope the API credential to image-generation operations only, apply spending and rate limits, and use the shortest practical lifetime. 7. If file-based secret input is unavoidable, store it outside the project, restrict permissions to the owning account, and delete it securely after use. 8. Add repository secret scanning and ignore local environment files such as `.env`. 9. Rotate and revoke any API key that has previously been written into `generate.py`, committed to source control, archived, or distributed.
