T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/main.mjs:4
- Finding
- API Credential Disclosure Through an Unrestricted Endpoint Override<![CDATA[ ## Vulnerability Details **File Location**: `scripts/main.mjs:4, 37-42` **Vulnerability Type**: Unvalidated API endpoint override resulting in credential and data disclosure **Risk Level**: High ### Vulnerable Code ```js const API_BASE = process.env.CRAZYROUTER_BASE_URL || "https://crazyrouter.com/v1"; ``` ```js const response = await fetch(`${API_BASE}/chat/completions`, { method: "POST", headers: { "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json" }, body: JSON.stringify({ model: args.model, messages: [{ role: "user", content: userContent }] }), }); ``` ### Technical Analysis The destination receiving the authenticated API request is controlled by the `CRAZYROUTER_BASE_URL` environment variable. The code does not validate the URL scheme, hostname, port, or origin before attaching the `CRAZYROUTER_API_KEY` as a bearer token. An attacker capable of setting or influencing this environment variable can redirect the request to an attacker-controlled HTTP server. The resulting request contains both the API credential and user-provided content, including the prompt, lyrics, and title. The override is not documented in `SKILL.md`, reducing the likelihood that users or operators will recognize that the credential can be sent to a destination other than Crazyrouter. Use of an `http://` URL would also transmit the credential and content without transport encryption. ### Attack Path 1. The attacker gains the ability to set or influence environment variables for the Skill invocation, deployment configuration, wrapper script, or Agent runtime. 2. The attacker sets `CRAZYROUTER_BASE_URL` to an endpoint under their control, such as `https://attacker.example/v1`. 3. A user invokes the Skill with a valid `CRAZYROUTER_API_KEY`. 4. The script sends a request to `https://attacker.example/v1/chat/completions`. 5. The request includes `Authorization: Bearer <CRAZYROUTER_API_KEY>`. 6. The request body also discloses the user's prompt, l ...[truncated 708 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Remove `CRAZYROUTER_BASE_URL` if endpoint customization is not required. - If endpoint customization is necessary, parse the value with the standard `URL` API and enforce: - The `https:` scheme. - An explicit allowlist of trusted hostnames. - An approved port, normally TCP 443. - An expected path prefix. - No embedded username or password. - Keep the credential scoped to Crazyrouter and do not attach it to requests whose origin differs from the approved API origin. - Explicitly validate redirect behavior. Disable redirects or reject any redirect that changes the trusted origin before resending an authorization header. - Document every supported environment variable and its security implications in `SKILL.md`. - Use a narrowly scoped API key where supported, apply usage limits, and rotate any key that may have been exposed. - Consider accepting endpoint changes only through trusted administrative configuration rather than the general process environment. ]]>
