T09 · Insecure Skill Coding Practices
- Location
scripts/ai_hive_mcp.py:19- Finding
Credential Exfiltration Through an Unvalidated MCP Endpoint Override
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ai_hive_mcp.py, lines 19 and 47–74
Vulnerability Type: Unvalidated destination for authenticated network requests
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", ) try: with urllib.request.urlopen(request, timeout=60) as response:Technical Analysis
The authenticated MCP destination is taken directly from the
AI_HIVE_MCP_URLenvironment variable without validating its scheme, hostname, port, path, or origin. Thepost()function then unconditionally attaches either theAI_HIVE_ACCESS_TOKENbearer token or theAI_HIVE_API_KEYheader to requests sent to that destination.Consequently, anyone able to influence the process environment can redirect authenticated requests away from the declared AI-HIVE service. The implementation does not require HTTPS, enforce an allowlist, or explicitly prevent credentials from being forwarded across redirects.
Although network access is necessary for the Skill's declared remote gener ...[truncated 1868 chars]
- Remediation
View remediation
Remediation Suggestions
-
Pin authenticated requests to the declared endpoint:
python MCP_URL = "https://ai-hive.iclip.cn/api/mcp" -
If endpoint overrides are operationally required, make them an explicit development-only option and validate the parsed URL:
- Require
https. - Require the exact allowlisted hostname.
- Reject embedded user information.
- Restrict ports and paths.
- Reject malformed or non-network URL schemes.
- Require
-
Disable automatic redirects for authenticated requests or validate every redirect target before following it. Never forward credentials when the destination origin changes.
-
Separate destination validation from request construction and fail closed before calling
auth_headers(). -
Add regression tests confirming rejection of:
- Plain HTTP endpoints.
- Foreign hostnames.
- Look-alike and suffix-confusion domains.
- URLs containing user information.
- Unexpected ports or paths.
- Cross-origin redirects.
-
Document that production users must not override the MCP endpoint and should revoke credentials immediately if an untrusted endpoint may have received them.
-
