T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/generate.js:3
- Finding
- Unvalidated API endpoint override can disclose credentials during music generation<![CDATA[ ## Vulnerability Details **File Location**: `scripts/generate.js`, lines 3-37 **Vulnerability Type**: Unvalidated credential-bearing network destination **Risk Level**: High ### Vulnerable Code ```js const API_BASE = process.env.MBM_API_BASE || "https://api.makebestmusic.com"; const API_KEY = process.env.apiKey; // ... 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 permits the API destination to be replaced through the undocumented `MBM_API_BASE` environment variable. It does not validate the URL scheme, hostname, port, or relationship to the official MakeBestMusic service. The same request sends the secret `apiKey` value as a bearer token. Consequently, any party capable of influencing the process environment can redirect the request to an arbitrary server and receive the credential. The override also permits a plaintext `http:` URL, which can expose the bearer token and prompt to network interception. Sending the API key and music prompt to the official MakeBestMusic HTTPS endpoint is necessary for the declared functionality. Allowing an unrestricted destination override exceeds that minimum requirement. ### Attack Path 1. An attacker, compromised launcher, unsafe configuration, or parent process sets `MBM_API_BASE` to an attacker-controlled URL. 2. The user requests music generation. 3. The Skill constructs the request using the attacker-controlled base URL. 4. The request includes `Authorization: Bearer <apiKey>` and the user’s music prompt. 5. The attacker’s server records the credential and request body. 6. The attacker may reuse the stolen credential ...[truncated 599 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the runtime endpoint override and use a fixed official HTTPS origin: ```js const API_BASE = "https://api.makebestmusic.com"; ``` 2. If endpoint configurability is required for controlled testing, parse the value with `URL` and enforce: - The `https:` protocol. - An explicit hostname allowlist. - Approved ports only. - No embedded username or password. 3. Use separate test credentials for non-production endpoints. Never send production credentials to development or user-selected servers. 4. Document every environment variable that affects network destinations. 5. Apply strict execution-environment controls so untrusted users and unrelated Skills cannot modify this process’s environment. 6. Consider short-lived, narrowly scoped credentials and server-side revocation support to limit the impact of accidental disclosure. ]]>
