T09 · Insecure Skill Coding Practices
- Location
scripts/run.js:272- Finding
Bearer Token Can Be Disclosed Through an Unrestricted Server Endpoint Override
- Content
View full analysis
Vulnerability Details
File Location:
scripts/run.js:59, 272-279
Vulnerability Type: Unrestricted authentication endpoint configuration
Risk Level: HighVulnerable Code
js const SERVER_BASE = process.env.KEYAPI_SERVER_URL ?? "https://mcp.keyapi.ai";js async function connect(serverUrl) { let token = process.env.KEYAPI_TOKEN; if (!token) token = await promptToken(); const client = new Client({ name: "keyapi-runner", version: "1.0.0" }); const transport = new StreamableHTTPClientTransport( new URL(serverUrl), { requestInit: { headers: { Authorization: `Bearer ${token}` } } } ); await client.connect(transport); return client; }The configured base is subsequently used without validation:
js const serverUrl = `${SERVER_BASE}/${values.platform}/mcp`; const client = await connect(serverUrl);Technical Analysis
KEYAPI_SERVER_URLmay specify an arbitrary origin or protocol. The connection routine unconditionally placesKEYAPI_TOKENin theAuthorizationheader, without requiring HTTPS, validating the destination hostname, or asking for confirmation before sending the credential to a non-default origin.Although sending the token to the documented
https://mcp.keyapi.aiservice is necessary for the Skill's declared functionality, transmitting it to an unrestricted override endpoint exceeds minimum privilege. A malicious or mistakenly configured.envfile, inherited environment variable, wrapper process, or deployment configuration can redirect authentication to an attacker-controlled service.Attack Path
- An attacker gains the ability to modify the project
.env, a launch script, container configuration, or another source of environment variables. - The attacker sets
KEYAPI_SERVER_URLto an attacker-controlled HTTPS endpoint or an interception-prone HTTP endpoint. - The victim invokes
scripts/run.jsfor any sup ...[truncated 799 chars]
- An attacker gains the ability to modify the project
- Remediation
View remediation
Remediation Suggestions
- Require the effective endpoint to use HTTPS.
- Allowlist
mcp.keyapi.aias the default and only automatic recipient ofKEYAPI_TOKEN. - Reject URLs containing embedded credentials, unexpected ports, fragments, or unsupported schemes.
- If custom enterprise endpoints are required, maintain an explicit allowlist or require informed user confirmation before sending the token to a different origin.
- Use separate credentials scoped to custom endpoints rather than reusing the production KeyAPI token.
- Validate the final URL after combining the base and platform path.
- Document the security implications of
KEYAPI_SERVER_URL. - Add tests confirming that HTTP endpoints and unapproved hosts cannot receive the authorization header.
- Rotate the token immediately if it may previously have been sent to an untrusted endpoint.
