T09 · Insecure Skill Coding Practices
- Location
scripts/ai_hive_mcp.py:15- Finding
Credential Disclosure Through an Unrestricted MCP Endpoint Override
- Content
View full analysis
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} ``` ```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", ) ``` ### Technical Analysis The MCP destination is taken directly from the `AI_HIVE_MCP_URL` environment variable without validating its scheme, hostname, port, or path. The script subsequently attaches either the complete AI-HIVE API key or OAuth access token to every request made to that destination. Authenticated network communication is necessary for the declared MCP functionality. However, allowing an unrestricted endpoint override while automatically attaching production credentials exceeds the minimum privileges required to communicate with the declared AI-HIVE service. Environment variables are not inherently trusted. They may be influenced by wrapper scripts, development environments, CI configuration, shell profiles, launchers, containers, or compromised parent processes. Consequently, an attacker capable of setting `AI_HIVE_MCP_URL` can redirect authenticat ...[truncated 1841 chars]- Remediation
View remediation
