T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/generate_image.py:13
- Finding
- Hardcoded Cloudflare API Credential in Source Code<![CDATA[ ## Vulnerability Details **File Location**: `scripts/generate_image.py`, lines 13-14 **Vulnerability Type**: Hardcoded bearer token and account identifier **Risk Level**: High ### Vulnerable Code ```python ACCOUNT_ID = "1e89d3ce76cbfef3b5c340e3984b7a52" TOKEN = "aCTA2KaKa1n3ayFDL-LPmZ-JgUC0HHgA5Msy18Bk" ``` ### Technical Analysis The script embeds a Cloudflare account identifier and bearer token directly in its source code. Any person or process capable of reading the skill package can recover and reuse the credential independently of the script. Source-controlled credentials are difficult to contain because they may remain in repository history, build artifacts, caches, backups, logs, or previously distributed copies even after being removed from the current version. The token's validity and exact permissions were not verified during this static audit, but an active token can authorize every operation included in its assigned Cloudflare scopes. ### Attack Path 1. An attacker obtains read access to the skill package, repository, archive, or a copied build artifact. 2. The attacker reads `scripts/generate_image.py` and extracts `ACCOUNT_ID` and `TOKEN`. 3. The attacker submits authenticated requests to Cloudflare using the exposed bearer token. 4. Cloudflare processes any request permitted by the token's configured scopes. 5. The attacker may continue using the token until it expires or is revoked. ### Impact Assessment If the token remains active, an attacker can consume Cloudflare Workers AI resources under the exposed account and potentially incur service costs, exhaust quotas, or disrupt legitimate usage. If the token has broader permissions than the image-generation operation requires, additional Cloudflare account resources within those scopes may also be exposed. This issue does not directly grant local operating-system privileges. Its external impact is bounded by the bearer token's effective Cloudflare permissions. ]]>
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Revoke and rotate the exposed token immediately; deleting it from the current file is insufficient once it has been distributed. 2. Review Cloudflare audit logs for unauthorized requests made with the credential. 3. Store the replacement credential in an environment variable or dedicated secret manager: ```python ACCOUNT_ID = os.environ["CLOUDFLARE_ACCOUNT_ID"] TOKEN = os.environ["CLOUDFLARE_API_TOKEN"] ``` 4. Fail securely with a clear configuration error when either variable is absent. 5. Grant the replacement token only the minimum permissions needed to invoke the required Workers AI model. 6. Add secret scanning to version-control and CI workflows, and purge the credential from repository history and distributed artifacts where feasible. 7. Avoid printing credentials or including them in exceptions, command lines, or logs. ]]>
