T09 · Insecure Skill Coding Practices
- Location
scripts/ai_hive_mcp.py:19- Finding
Environment-Controlled MCP Endpoint Can Receive API Credentials
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ai_hive_mcp.py, lines 19 and 46–70
Vulnerability Type: Credential disclosure through an unvalidated network destination
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 read directly from the
AI_HIVE_MCP_URLenvironment variable. The value is not restricted to HTTPS and is not checked against the documented AI-HIVE hostname or origin.At the same time, every request made by
post()unconditionally includes either the bearer access token or the API key returned byauth_headers(). User-selected tool arguments are also serialized into the request body.Consequently, a manipulated or unexpectedly inherited environment can redirect both credentials and request data to an arbitrary server. Allowing an unrestricted endpoint override exceeds the minimum privileges required for this Skill because its declared functionality uses only the official
https://ai-hive.iclip.cn/api/mcpservice....[truncated 1493 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the
AI_HIVE_MCP_URLoverride if alternative MCP servers are not required:
python MCP_URL = "https://ai-hive.iclip.cn/api/mcp"- If endpoint configurability is required, validate the parsed destination before attaching credentials:
python from urllib.parse import urlparse ALLOWED_HOSTS = {"ai-hive.iclip.cn"} def validate_mcp_url(url: str) -> str: parsed = urlparse(url) if ( parsed.scheme != "https" or parsed.hostname not in ALLOWED_HOSTS or parsed.port not in (None, 443) or parsed.username is not None or parsed.password is not None ): raise SystemExit("Refusing to send credentials to an unapproved MCP endpoint.") return url-
Bind credentials to an exact approved origin. Do not attach the API key or bearer token when the request destination differs from
https://ai-hive.iclip.cn. -
Disable or carefully validate HTTP redirects for authenticated requests so credentials cannot be forwarded to another origin.
-
Require an explicit command-line opt-in for any nonproduction endpoint, and use separate test credentials with minimal permissions rather than production credentials.
-
Document that users should clear unexpected
AI_HIVE_MCP_URLvalues and inspect inherited environments when running the helper from wrappers, CI systems, or shared shells. -
Prefer short-lived, narrowly scoped OAuth tokens where supported, and retain the existing guidance for immediate credential revocation after suspected exposure.
- Remove the
