T09 · Insecure Skill Coding Practices
- Location
scripts/run.js:59- Finding
Unrestricted MCP Endpoint Override Can Disclose the KeyAPI Bearer Token
- Content
View full analysis
Vulnerability Details
File Location:
scripts/run.js:59,scripts/run.js:272-280, andscripts/run.js:509-510
Vulnerability Type: Unvalidated credential destination and insecure server 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; }js const serverUrl = `${SERVER_BASE}/${values.platform}/mcp`; const client = await connect(serverUrl);Technical Analysis
The runner accepts
KEYAPI_SERVER_URLdirectly from the process environment and does not validate its scheme, hostname, port, or origin. Theconnectfunction then unconditionally attaches the productionKEYAPI_TOKENas a bearer credential to the resulting URL.Network communication with the documented KeyAPI endpoint is necessary for the Skill's declared LinkedIn analytics functionality. However, forwarding the same credential to an arbitrary endpoint is not necessary and exceeds the minimum trust boundary. The implementation permits both attacker-controlled HTTPS destinations and plaintext HTTP destinations if supported by the transport.
This vulnerability is exploitable when an attacker can influence the process environment, deployment configuration, wrapper script, CI job, container configuration, or command-launching context. No ability to modify the Skill source code is required.
Attack Path
- The attacker obtains influence over the environment used to launch the Skill.
- The attacker sets `KEYAPI_SERVER_ ...[truncated 934 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove
KEYAPI_SERVER_URLsupport unless custom MCP servers are an explicit functional requirement. - Require HTTPS and reject URLs using HTTP or other schemes.
- Allowlist the documented hostname,
mcp.keyapi.ai, before attachingKEYAPI_TOKEN. - Normalize and validate the URL with the
URLAPI, including hostname, protocol, port, username, and password fields. - Never send the production KeyAPI token to a custom endpoint. If custom servers must be supported, require a separate credential through a distinct environment variable.
- Fail closed when endpoint validation fails and clearly identify the rejected destination.
- Document the trust implications of endpoint overrides and avoid inheriting them from untrusted environment files or wrappers.
- Add automated tests confirming that credentials are not attached to non-allowlisted origins.
A hardened design should conceptually enforce the following:
js const DEFAULT_SERVER_BASE = "https://mcp.keyapi.ai"; const parsedBase = new URL(process.env.KEYAPI_SERVER_URL ?? DEFAULT_SERVER_BASE); if ( parsedBase.protocol !== "https:" || parsedBase.hostname !== "mcp.keyapi.ai" || parsedBase.username || parsedBase.password ) { throw new Error("Untrusted KeyAPI server URL"); }If a custom endpoint is selected, the application should refuse to reuse
KEYAPI_TOKEN.- Remove
