T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/daily_report.py:7
- Finding
- Grok API Credential Is Transmitted to a Third-Party Endpoint by Default<![CDATA[ ## Vulnerability Details **File Location**: `scripts/daily_report.py:7-8` and `scripts/daily_report.py:67-83`; documented in `SKILL.md:14-16` and `README.md:7-16` **Vulnerability Type**: Credential exposure through an untrusted configurable API endpoint **Risk Level**: High ### Vulnerable Code ```python API_URL = os.getenv("GROK_API_URL", "https://api.cheaprouter.club/v1/chat/completions") API_KEY = os.getenv("GROK_API_KEY") ``` ```python def query_grok(prompt): headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } payload = { "model": MODEL, "messages": [{"role": "user", "content": prompt}], "temperature": 0.7, "stream": True } response = requests.post(API_URL, headers=headers, json=payload, timeout=180, stream=True) ``` The setup documentation reinforces this configuration: ```bash export GROK_API_KEY="your-api-key-here" export GROK_API_URL="https://api.cheaprouter.club/v1/chat/completions" # optional ``` ### Technical Analysis The script describes `GROK_API_KEY` as a Grok API credential but sends it in an HTTP `Authorization: Bearer` header to `api.cheaprouter.club`, an intermediary domain rather than an official provider endpoint. Because this third-party endpoint is the default, users following the documented setup may unknowingly disclose a provider credential to the router. The endpoint can also be replaced through `GROK_API_URL` without any hostname allowlist, trust validation, or warning. Although HTTPS protects the request in transit, it does not protect the credential from the configured endpoint itself. Any server selected through this variable receives both the bearer credential and the complete prompt. ### Attack Path 1. A user follows the project documentation and exports a valid credential as `GROK_API_KEY`. 2. The user runs `python3 scripts/daily_report.py` without overriding `GROK_API_URL`, or runs it in an enviro ...[truncated 1171 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Replace the third-party default with the official provider endpoint appropriate for `GROK_API_KEY`. 2. If third-party routing is intentionally supported, use a router-specific credential rather than instructing users to supply a reusable provider credential. 3. Remove the custom endpoint default and require users to opt in explicitly to third-party routing. 4. Validate `GROK_API_URL` before transmitting credentials: - Require HTTPS. - Parse the URL rather than using string-prefix checks. - Maintain an explicit allowlist of trusted hostnames. - Reject embedded credentials, unexpected ports, redirects to untrusted origins, and malformed hosts. 5. Disable automatic cross-origin redirects or verify the destination after every redirect so that authorization headers cannot reach an unintended host. 6. Display a clear warning and require explicit confirmation before sending a credential to a non-official endpoint. 7. Document the credential trust boundary, expected issuer, required minimum permissions, rotation procedure, and revocation procedure. 8. Recommend narrowly scoped, short-lived credentials and ensure affected users rotate any key previously sent to an endpoint they do not trust. ]]>
