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:19, 47-52, 61-74
Vulnerability Type: Unvalidated network destination for sensitive authentication headers
Risk Level: MediumVulnerable Code
python MCP_URL = os.environ.get("AI_HIVE_MCP_URL", "https://ai-hive.iclip.cn/api/mcp")python def auth_headers() -> dict[str, str]: 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} raise SystemExit( "缺少凭据。OAuth 用户请在 MCP 客户端中完成登录;本脚本调用工具时需通过环境变量提供 " "AI_HIVE_API_KEY,或仅运行 doctor。" )python def post(payload: dict, session_id: str | None = None) -> tuple[dict, str | None]: 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 bearer token from environment variables and attaches it to every MCP POST request. However, the request destination is also controlled by the
AI_HIVE_MCP_URLenvironment variable and is not validated before credentials are transmitted.An attacker who can influence the process environment or its launcher can replace the official AI-HIVE endpoint with an attacker-controlled URL. The script does not enforce HTTPS, restrict the hostname and path to the ...[truncated 1877 chars]
- Remediation
View remediation
Remediation Suggestions
-
Remove
AI_HIVE_MCP_URLconfigurability if custom servers are not a documented requirement, and use the fixed official endpoint:python MCP_URL = "https://ai-hive.iclip.cn/api/mcp" -
If endpoint customization is required, parse and validate the URL before constructing a request:
- Require the
httpsscheme. - Allowlist the exact expected hostname.
- Require the expected
/api/mcppath. - Reject embedded user information.
- Reject fragments, unexpected query parameters, and nonstandard ports.
- Normalize the hostname before comparison.
- Require the
-
Do not send AI-HIVE credentials to custom or untrusted endpoints. Use endpoint-specific credentials if third-party MCP servers must be supported.
-
Disable automatic cross-origin redirects for authenticated requests, or validate every redirect target and strip authentication headers whenever the origin changes.
-
Fail closed with a clear error when endpoint validation fails. If a nonstandard endpoint is intentionally supported, require explicit interactive confirmation that identifies the destination and states that credentials and request data will be transmitted.
-
Add tests covering HTTP endpoints, lookalike domains, user-information syntax, alternate ports, malformed URLs, and cross-origin redirects.
-
