T09 · Insecure Skill Coding Practices
- Location
scripts/run.js:60- Finding
Bearer Token Can Be Transmitted to an Arbitrary Server Through an Unrestricted Endpoint Override
- Content
View full analysis
Vulnerability Details
File Location:
scripts/run.js, lines 60 and 509-510; credential attachment occurs in theconnectfunction around lines 241-286
Vulnerability Type: Unrestricted credential-bearing network destination
Risk Level: MediumRelevant Code
javascript const SERVER_BASE = process.env.KEYAPI_SERVER_URL ?? "https://mcp.keyapi.ai";javascript 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; }javascript const serverUrl = `${SERVER_BASE}/${values.platform}/mcp`; const client = await connect(serverUrl);Technical Analysis
Sending
KEYAPI_TOKENto the documented KeyAPI MCP service is necessary for the declared search functionality. However, the destination is taken directly fromKEYAPI_SERVER_URLwithout enforcing HTTPS or verifying that the host belongs to KeyAPI.Consequently, the same bearer credential is attached to requests sent to any configured URL, including an attacker-controlled HTTPS endpoint or an unencrypted HTTP endpoint. A fixed KeyAPI endpoint or a narrowly validated override would provide the required functionality with less privilege and lower credential exposure.
The environment override is not inherently malicious, and an attacker who can directly inspect the victim's complete process environment may already have access to the token. The material exploitation case is an attacker who can influence configuration, deployment instructions, shell initialization, or a local
.envfile without otherwise being able to read the victim's token.Attack Path
- An attacker persua ...[truncated 966 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove
KEYAPI_SERVER_URLunless custom endpoints are an essential supported feature. - Prefer the fixed documented endpoint:
https://mcp.keyapi.ai. - If overrides are necessary, parse the URL before attaching credentials and require:
https:as the protocol;- an explicit allowlist of trusted hostnames;
- no embedded username or password;
- an expected port and pathname.
- Do not forward the production bearer token to arbitrary development endpoints. Use a separate, explicitly named development credential where custom servers are required.
- Fail closed on malformed URLs, redirects to untrusted hosts, and TLS validation errors.
- Document the security implications of endpoint overrides and avoid accepting them from untrusted project-local configuration.
- Remove
