T09 · Insecure Skill Coding Practices
- Location
scripts/run.js:272- Finding
Bearer Token Can Be Redirected to an Arbitrary Server
- Content
View full analysis
Vulnerability Details
File Location:
scripts/run.js, lines 59 and 272–279
Vulnerability Type: Unvalidated credential destination
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}` } } } );Technical Analysis
Sending
KEYAPI_TOKENto the documented KeyAPI endpoint is necessary for the Skill's declared functionality. However,KEYAPI_SERVER_URLcontrols the destination without protocol or hostname validation. The bearer token is unconditionally attached to requests sent through the resulting transport.Consequently, an attacker who can influence the process environment can redirect authentication requests to an attacker-controlled server. The implementation does not restrict the destination to
https://mcp.keyapi.ai, enforce HTTPS, or require user confirmation before sending the credential to an override endpoint.Attack Path
- An attacker influences the environment used to launch the Skill, such as through a compromised wrapper, shell configuration, CI configuration, or launcher.
- The attacker sets
KEYAPI_SERVER_URLto an endpoint under their control. - The user invokes
scripts/run.jswith a validKEYAPI_TOKEN. - The script constructs the MCP URL from the attacker-controlled base URL and selected platform.
connect()attachesAuthorization: Bearer <KEYAPI_TOKEN>to the transport.- The attacker-controlled server receives and records the bearer token.
- The attacker reuses the token against KeyAPI until it is revoked or expires.
...[truncated 625 chars]
- Remediation
View remediation
Remediation Suggestions
- Restrict credential-bearing connections to an explicit hostname allowlist, preferably only
mcp.keyapi.ai. - Require the effective URL to use HTTPS.
- Parse and validate the complete URL before constructing the transport:
- Require
url.protocol === "https:". - Require
url.hostname === "mcp.keyapi.ai"or another explicitly trusted hostname. - Reject embedded credentials and unexpected ports.
- Require
- If custom endpoints are operationally required, do not automatically forward
KEYAPI_TOKEN. Use a separate credential variable for custom servers and display an explicit warning or confirmation prompt. - Log the effective destination hostname before connecting, without logging the token.
- Document the trust implications of endpoint overrides and recommend clearing inherited environment variables in privileged or automated execution contexts.
- Restrict credential-bearing connections to an explicit hostname allowlist, preferably only
