T09 · Insecure Skill Coding Practices
- Location
scripts/generate_image.py:13- Finding
Hardcoded Cloudflare API Credentials
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate_image.py, lines 13–15 and 24–29
Vulnerability Type: Hardcoded cloud credentials
Risk Level: HighVulnerable Code:
python # Credentials (Hardcoded as requested) ACCOUNT_ID = "1e89d3ce76cbfef3b5c340e3984b7a52" TOKEN = "aCTA2KaKa1n3ayFDL-LPmZ-JgUC0HHgA5Msy18Bk" MODEL = "@cf/black-forest-labs/flux-1-schnell"The credential is subsequently placed in an HTTP authorization header:
python cmd = f'''curl -s -X POST "https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/{MODEL}" \ -H "Authorization: Bearer {TOKEN}" \ -H "Content-Type: application/json" \ -d '{json.dumps({"prompt": prompt})}' > /tmp/cf_response.json'''Technical Analysis
A Cloudflare account identifier and live-looking bearer token are embedded directly in distributable source code. Any user who can download, inspect, fork, archive, or otherwise access the skill package can retrieve the token without authentication.
Bearer tokens grant access based on possession. The source code imposes no additional access control, host binding, or caller verification. The actual scope of compromise depends on permissions assigned to the token in Cloudflare, but the code proves that it can at least be presented to the Workers AI endpoint for the identified account.
Attack Path
- An attacker obtains a copy of the skill package or views its source.
- The attacker reads
ACCOUNT_IDandTOKENfromscripts/generate_image.py. - The attacker submits independent API requests using the exposed bearer token.
- Requests are executed against the associated Cloudflare account within the token's configured permissions.
- The attacker may continue using the credential until it expires or is revoked.
Impact Assessment
The confirmed scope includes possible unauthorized use of Cloudflare Workers AI under the affected account. This can consume quot ...[truncated 409 chars]
- Remediation
View remediation
Remediation Suggestions
- Revoke the exposed token immediately and issue a replacement; removing it from the current file does not invalidate copies in archives or version history.
- Store the replacement in a secret manager or protected environment variable, such as
CLOUDFLARE_API_TOKEN. - Fail safely when the required secret is absent rather than supplying a fallback credential.
- Create a dedicated token restricted to the minimum account, API, and operation scopes required for Workers AI.
- Configure expiration and rotation policies for the replacement token.
- Remove the credential from all repository history and published artifacts where feasible.
- Add automated secret scanning to development and release workflows.
- Review Cloudflare audit and billing logs for unauthorized activity involving the exposed token.
Example:
python ACCOUNT_ID = os.environ["CLOUDFLARE_ACCOUNT_ID"] TOKEN = os.environ["CLOUDFLARE_API_TOKEN"]
