T09 · Insecure Skill Coding Practices
- Location
scripts/run.js:58- Finding
Bearer Token Disclosure Through an Unrestricted Server Override
- Content
View full analysis
Vulnerability Details
File Location:
scripts/run.js, lines 58 and 290–294, with the constructed endpoint used at lines 503–504
Vulnerability Type: Unrestricted credential destination / sensitive information exposure
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 allows
KEYAPI_SERVER_URLto replace the intendedhttps://mcp.keyapi.aiservice without validating the URL scheme, hostname, port, or origin. Theconnectfunction then unconditionally attachesKEYAPI_TOKENas a bearer credential to requests sent through the configured endpoint.The project also automatically imports variables from a project-local
.envfile. Consequently, anyone able to influence the process environment or that file can redirect authenticated requests to an arbitrary server. An HTTP destination is also accepted, potentially exposing the token and query data to passive network interception.A server override can be useful for testing, but forwarding a production bearer credential to any configured origin exceeds the minimum network privilege required for the Skill’s declared TikTok intelligence functionality.
Attack Path
- An attacker gains the ability to modify the project-local
.envfile, deployment environment, wrapper script, or process configuration. - The attacker sets
KEYAPI_SERVER_URLto an attacker-controlled en ...[truncated 1355 chars]
- An attacker gains the ability to modify the project-local
- Remediation
View remediation
Remediation Suggestions
- Remove
KEYAPI_SERVER_URLif alternate MCP origins are not essential. - If an override is required, parse it with
URLand enforce:- The
https:protocol. - An explicit allowlist of trusted hostnames.
- Approved ports only.
- No embedded username or password.
- No unexpected path, query string, or fragment.
- The
- Bind credentials to origins. Attach
KEYAPI_TOKENonly when the final normalized origin exactly matches an approved KeyAPI origin. - Use a separate, low-privilege test credential for development or staging endpoints rather than forwarding the production token.
- Reject invalid configuration before initializing the MCP transport and display the rejected origin without printing the token.
- Document the trusted endpoint policy and ensure environment or
.envconfiguration is not writable by untrusted users. - Add automated tests proving that HTTP URLs, lookalike domains, unapproved ports, embedded credentials, and arbitrary external hosts are rejected.
A suitable validation pattern is:
js const TRUSTED_ORIGINS = new Set(["https://mcp.keyapi.ai"]); function validateServerBase(value) { const url = new URL(value); if ( url.protocol !== "https:" || !TRUSTED_ORIGINS.has(url.origin) || url.username || url.password || url.search || url.hash ) { throw new Error("Untrusted KEYAPI server URL"); } return url.origin; }The authorization header should only be created after this validation succeeds.
- Remove
