T09 · Insecure Skill Coding Practices
- Location
scripts/ai_hive_mcp.py:19- Finding
Unvalidated MCP endpoint override can disclose credentials and task data
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ai_hive_mcp.py:19, 47-72
Vulnerability Type: Unvalidated security-sensitive endpoint configuration
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。" ) 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", )Technical Analysis
The MCP destination is taken directly from the
AI_HIVE_MCP_URLenvironment variable. The value is not validated against the Skill's declared endpoint,https://ai-hive.iclip.cn/api/mcp, and there is no requirement that it use HTTPS.The
post()function unconditionally adds either the bearer access token or AI-HIVE API key to requests sent to that configured destination. It also sends MCP initialization data and subsequent tool-call arguments to the same destination. Consequently, an attacker who can influence the process environment can redirect security-sensitive requests to an arbitrary server.This behavior exceeds the minimum privilege required by the declared functionality. The Skil ...[truncated 1739 chars]
- Remediation
View remediation
Remediation Suggestions
-
Remove the
AI_HIVE_MCP_URLoverride if custom endpoints are not an explicit requirement:python MCP_URL = "https://ai-hive.iclip.cn/api/mcp" -
If endpoint configurability is required, validate the parsed URL before attaching credentials:
- Require the
httpsscheme. - Require the exact approved hostname
ai-hive.iclip.cn. - Require the expected
/api/mcppath. - Reject embedded user information, unexpected ports, fragments, and ambiguous hostnames.
- Require the
-
Separate endpoint selection from credential forwarding. Authentication headers should only be added after the destination has passed the allowlist check.
-
Disable automatic redirects or validate every redirect destination before forwarding credentials. Reject cross-origin redirects.
-
Emit a clear error when the endpoint does not match the approved service rather than silently accepting an override.
-
Add tests covering plain HTTP, lookalike domains, alternate ports, user-information syntax, malformed URLs, and cross-origin redirects.
-
