T09 · Insecure Skill Coding Practices
- Location
scripts/run.js:285- Finding
Bearer Token Disclosure Through Arbitrary MCP Server Override
- Content
View full analysis
Vulnerability Details
File Location:
scripts/run.js:58,scripts/run.js:285-291, andscripts/run.js:509-510
Vulnerability Type: Credential exfiltration through an unrestricted network 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}` } } } );js const serverUrl = `${SERVER_BASE}/${values.platform}/mcp`; const client = await connect(serverUrl);Technical Analysis
The code permits
KEYAPI_SERVER_URLto replace the trusted KeyAPI MCP origin. Regardless of the selected origin,connect()attaches the productionKEYAPI_TOKENas anAuthorizationbearer credential.No hostname allowlist, HTTPS requirement, certificate pinning, destination confirmation, or separation between production and custom-server credentials is implemented. Consequently, an actor capable of influencing the process environment can direct authenticated requests to an attacker-controlled server.
A server override may be useful during development, but forwarding the primary API credential to an unrestricted destination exceeds the minimum privileges required for the declared Threads discovery functionality.
Attack Path
- The attacker gains the ability to influence the environment used to launch the Skill, such as through a wrapper script, CI configuration, container environment, or compromised shell configuration.
- The attacker sets
KEYAPI_SERVER_URLto an attacker-controlled HTTP or HTTPS endpoint. - A user invokes the Skill to list tools, retrieve a schema, ...[truncated 721 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove
KEYAPI_SERVER_URLin production builds and use a fixed trusted endpoint. - If overrides are operationally necessary, parse the URL and require:
- The
https:protocol. - An exact hostname from a documented allowlist.
- An expected port and path.
- Rejection of embedded credentials and unexpected URL components.
- The
- Do not send
KEYAPI_TOKENto custom endpoints. Require a separate credential specifically configured for the custom server. - Require explicit interactive confirmation before connecting to a non-default origin and display the exact destination without displaying the token.
- Treat environment configuration as untrusted input and document the security implications of endpoint overrides.
- Rotate the token immediately if it may have been sent to an untrusted endpoint.
- Remove
