T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/generate.js:3
- Finding
- Configurable API endpoint can disclose the API credential and user prompts<![CDATA[ ## Vulnerability Details **File Location**: `scripts/generate.js`, lines 3 and 22-36 **Vulnerability Type**: Unrestricted destination for authenticated network requests **Risk Level**: High ### Vulnerable Code ```js const API_BASE = process.env.MBM_API_BASE || "https://api.makebestmusic.com"; ``` ```js const res = await fetch(`${API_BASE}/api/skill/generate_music`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${API_KEY}`, }, body: JSON.stringify({ model: "Fi", custom: true, instrumental: instrumental, prompt: prompt, title: "", style: "", advance: { vocal_gender: "", ai_lyrics: true } }), }); ``` ### Technical Analysis The script obtains its API destination from the unrestricted `MBM_API_BASE` environment variable. It then sends the MakeBestMusic API key in an `Authorization` header and the user's music prompt in the request body to that destination. The endpoint override is not documented as part of the Skill's declared functionality and is unnecessary for normal operation. No validation ensures that the destination uses HTTPS or belongs to the official `api.makebestmusic.com` origin. Consequently, a process or configuration source capable of setting `MBM_API_BASE` can redirect the authenticated request to an arbitrary server. A plaintext HTTP URL would also expose the credential and prompt to interception. Sending the credential to the official HTTPS service is necessary for music generation. Allowing arbitrary destinations to receive that credential exceeds the minimum privilege required. ### Attack Path 1. An attacker gains influence over the environment used to launch the Skill, such as through a compromised launcher, unsafe configuration, or inherited environment variable. 2. The attacker sets `MBM_API_BASE` to an attacker-controlled URL, for example `https://attacker.example`. 3. A user asks the Skill to generate music. 4. `generate. ...[truncated 845 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the runtime endpoint override and use the fixed official origin: ```js const API_BASE = "https://api.makebestmusic.com"; ``` 2. If an override is genuinely required for controlled development or testing, validate it before reading or transmitting the API key: ```js const allowedOrigins = new Set([ "https://api.makebestmusic.com" ]); const apiUrl = new URL( process.env.MBM_API_BASE || "https://api.makebestmusic.com" ); if (apiUrl.protocol !== "https:" || !allowedOrigins.has(apiUrl.origin)) { throw new Error("Untrusted MakeBestMusic API endpoint"); } ``` 3. Reject plaintext HTTP, embedded URL credentials, unexpected ports, redirects to other origins, and hostnames not present in an explicit allowlist. 4. Disable automatic cross-origin redirects or verify the final destination before forwarding the `Authorization` header. 5. Read the API key only after the destination has passed validation. 6. Rotate any API key that may have been used while `MBM_API_BASE` pointed to an untrusted endpoint. 7. Document all data sent to the provider, including the prompt and generation options. ]]>
