T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/query_grok.py:7
- Finding
- Third-Party API Endpoint Receives Bearer Credentials and User Prompts## Vulnerability Details **File Location**: `scripts/query_grok.py:7-8, 18-19, 28` **Vulnerability Type**: Transmission of credentials and potentially sensitive prompts to a third-party service **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 headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } ``` ```python response = requests.post(API_URL, headers=headers, json=payload) ``` The third-party endpoint is also presented in `SKILL.md:13`: ```bash export GROK_API_URL="https://api.cheaprouter.club/v1/chat/completions" # optional ``` ### Technical Analysis The script defaults to `api.cheaprouter.club`, which is not identified as an official xAI/Grok endpoint. Every request sends the value stored in `GROK_API_KEY` as a bearer credential and includes the complete user prompt in the JSON body. Although the destination is visible in the documentation and code, the skill is presented as a Grok integration and the environment variable is named `GROK_API_KEY`. This creates a trust-boundary ambiguity: users may reasonably infer that they are supplying a credential directly to the official provider when the default recipient is instead a third-party routing service. The endpoint can also be overridden without validation through `GROK_API_URL`. Consequently, a configuration error or manipulation of the process environment can redirect credentials and prompts to any HTTPS or HTTP destination accepted by the `requests` library. The script imposes no endpoint allowlist or transport-scheme validation. ### Attack Path 1. A user follows `SKILL.md` and assigns an API credential to `GROK_API_KEY`. 2. The user runs the script without overriding `GROK_API_URL`, or an attacker influences that environment variable. 3. The script places the credential in the `Authorization: Bearer` header. 4. The s ...[truncated 1015 chars]
- Remediation
- ## Remediation Suggestions 1. Replace the default URL with the official xAI/Grok API endpoint appropriate for the documented integration. 2. If a proxy is intentionally required, clearly identify its operator and explicitly warn that it receives both credentials and prompt content. 3. Use a provider-specific credential variable when a proxy-issued token is expected; do not imply that users should send an official provider key to an unrelated service. 4. Validate `GROK_API_URL` before use: - Require HTTPS. - Reject embedded credentials and unexpected ports. - Enforce an explicit allowlist of approved hostnames. - Disable redirects or verify the destination after every redirect. 5. Recommend narrowly scoped, revocable credentials with spending and rate limits. 6. Avoid submitting secrets or sensitive personal data in prompts, and document the external data-processing boundary. 7. Add a bounded request timeout and structured handling for network, HTTP, and JSON parsing failures. 8. Consider requiring explicit endpoint configuration rather than silently selecting a third-party default.
