T09 · Insecure Skill Coding Practices
- Location
scripts/ai_hive_mcp.py:19- Finding
Unrestricted MCP Endpoint Override Can Expose Authentication Credentials
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ai_hive_mcp.py, lines 19 and 47–71
Vulnerability Type: Credential disclosure through an unvalidated network destination
Risk Level: HighVulnerable 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 without validating its scheme, hostname, port, or path. Thepost()function independently obtains an API key or OAuth access token and automatically places it in the request headers sent to that configurable destination.Consequently, the code does not bind AI-HIVE credentials to the intended origin,
https://ai-hive.iclip.cn. Any party capable of influencing the process environment or launch configuration can redirect authenticated MCP requests to another server. HTTPS alone does not prevent this issue because an attacker-controlled HTTPS server can possess its own valid certificate.This flexibility exceeds the minimum privileges required by the declared fun ...[truncated 1374 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the
AI_HIVE_MCP_URLoverride if custom endpoints are not essential:
python MCP_URL = "https://ai-hive.iclip.cn/api/mcp"-
If configurability is required, parse and strictly validate the URL before constructing an authenticated request:
- Require
https. - Allowlist
ai-hive.iclip.cn. - Reject embedded user information, unexpected ports, fragments, and malformed hosts.
- Prefer an exact allowed origin and path.
- Require
-
Bind credentials to an approved origin and refuse to add authentication headers for any other destination.
-
Disable automatic cross-origin redirects for authenticated requests, or verify every redirect target before forwarding credentials.
-
Require a separate, explicit opt-in for custom development endpoints. Do not reuse production credentials with them; require dedicated test credentials.
-
Document that
AI_HIVE_MCP_URLis security-sensitive and must not be accepted from untrusted project-level environment files, wrappers, or CI variables. -
Add automated tests confirming that:
- HTTP endpoints are rejected.
- Lookalike and subdomain-confusion hosts are rejected.
- Alternate ports and user-info URLs are rejected.
- Authentication headers are never sent after a cross-origin redirect.
- The documented AI-HIVE HTTPS endpoint remains functional.
- Remove the
