T09 · Insecure Skill Coding Practices
- Location
scripts/ai_hive_mcp.py:19- Finding
Credential Disclosure Through an Unrestricted MCP Endpoint Override
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ai_hive_mcp.py, lines 19 and 47–74
Vulnerability Type: Authenticated requests sent to an unrestricted, environment-controlled destination
Risk Level: MediumVulnerable Code
python MCP_URL = os.environ.get("AI_HIVE_MCP_URL", "https://ai-hive.iclip.cn/api/mcp")python key = os.environ.get("AI_HIVE_API_KEY", "").strip() token = os.environ.get("AI_HIVE_ACCESS_TOKEN", "").strip() if token: return {"authorization": f"Bearer {token}"} if key: return {"x-ai-hive-api-key": key}python headers = { "content-type": "application/json", "accept": "application/json, text/event-stream", **auth_headers(), } if session_id: headers["mcp-session-id"] = session_id request = urllib.request.Request( MCP_URL, data=json.dumps(payload, ensure_ascii=False).encode("utf-8"), headers=headers, method="POST", ) try: with urllib.request.urlopen(request, timeout=60) as response: result = parse_payload(response.read(), response.headers.get("content-type", "")) return result, response.headers.get("mcp-session-id") or session_idTechnical Analysis
The script obtains an API key or OAuth access token from the process environment and attaches it to every MCP request. However, the destination of those authenticated requests can independently be replaced through the
AI_HIVE_MCP_URLenvironment variable.The replacement URL is not validated before authentication headers are constructed and transmitted. There is no enforcement of:
- The HTTPS scheme
- The expected
ai-hive.iclip.cnhostname - The expected
/api/mcppath - An approved destination allowlist
- Same-origin redirect behavior
Consequently, a process or configuration source capable of setting
AI_HIVE_MCP_URLcan direct the API key or bearer token to an attacker-controlled server. The documented Ski ...[truncated 2167 chars]- Remediation
View remediation
Remediation Suggestions
-
Remove the
AI_HIVE_MCP_URLoverride if custom endpoints are not required:python MCP_URL = "https://ai-hive.iclip.cn/api/mcp" -
If endpoint configuration is required, validate it before constructing or attaching authentication headers:
- Require
https. - Require the exact hostname
ai-hive.iclip.cn. - Require the expected port and
/api/mcppath. - Reject embedded credentials, fragments, unexpected query parameters, and malformed hostnames.
- Use an explicit allowlist rather than suffix matching.
- Require
-
Disable cross-origin redirects for credentialed requests. If redirects are needed, only follow redirects that preserve the approved scheme, hostname, port, and path policy.
-
Separate test and production behavior:
- Do not attach real credentials when a custom test endpoint is configured.
- Require an explicit development mode and a dedicated non-production credential for test servers.
-
Apply least-privilege server-side controls:
- Use narrowly scoped, short-lived tokens where possible.
- Separate read-only model-listing access from generation permissions.
- Enforce billing limits and operation-level authorization on the server.
- Revoke and rotate any credential suspected of exposure.
-
Add automated tests confirming that authenticated requests are rejected for HTTP URLs, lookalike domains, altered ports, unexpected paths, and cross-origin redirects.
-
