T09 · Insecure Skill Coding Practices
- Location
scripts/run.js:274- Finding
Bearer Token Can Be Redirected to an Arbitrary Server
- Content
View full analysis
Vulnerability Details
File Location:
scripts/run.js:59,scripts/run.js:274-279, andscripts/run.js:515-516
Vulnerability Type: Unvalidated authentication endpoint override
Risk Level: MediumVulnerable 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; }js const serverUrl = `${SERVER_BASE}/${values.platform}/mcp`; const client = await connect(serverUrl);Technical Analysis
The runner reads
KEYAPI_SERVER_URLfrom the process environment and uses it without validating the URL scheme or destination host. Theconnect()function then unconditionally attaches the productionKEYAPI_TOKENas a bearer credential to requests sent to that destination.The documented functionality only requires authentication to
https://mcp.keyapi.ai. Allowing an arbitrary environment-selected endpoint to receive the credential exceeds the minimum privileges needed for that functionality. Environment variables may be influenced by shell profiles, CI configuration, wrapper scripts, container configuration, or copied setup commands.Although sending the token to the legitimate KeyAPI service is necessary and disclosed, sending it to an unrestricted override destination is not.
Attack Path
- An attacker gains influence over the execution environment, a wrapper script, CI configuration, or instructions used to launch the Skill.
- The attacker sets
KEYAPI_SERVER_URLto an attacker-controlled endpoint. - The user invokes
--list-tools,--schema, or a tool operation. - The runner constr ...[truncated 743 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove
KEYAPI_SERVER_URLsupport if custom endpoints are not essential. - If overrides are required, parse the URL and enforce:
- The
https:scheme. - An explicit allowlist containing
mcp.keyapi.ai. - Rejection of embedded credentials, unexpected ports, and malformed hostnames.
- The
- Never send
KEYAPI_TOKENto a custom or untrusted endpoint. - Require a separate environment variable, such as
CUSTOM_MCP_TOKEN, for explicitly approved custom servers. - Require an explicit command-line opt-in before connecting to a non-default server and display the exact destination receiving authentication.
- Add automated tests confirming that HTTP URLs, lookalike domains, subdomain confusion, and non-allowlisted hosts are rejected.
- Remove
