T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/call_api.py:52
- Finding
- Configurable API Endpoint Can Expose Credentials and Submitted Images<![CDATA[ ## Vulnerability Details **File Location**: `scripts/config.py:9-19`, `scripts/call_api.py:52-71` **Vulnerability Type**: Unvalidated credential-bearing endpoint configuration **Risk Level**: High ### Vulnerable Code ```python # scripts/config.py:9-19 model_config = SettingsConfigDict( env_prefix="XBY_GAOKAO_", env_file=".env", env_file_encoding="utf-8", extra="ignore", ) # API configuration base_url: str = "https://mcp.xiaobenyang.com" mcp_id: str = "1820705335657482" api_key: str = "" ``` ```python # scripts/call_api.py:52-71 url = f"{settings.base_url}/api" mcp_id = mcp_id or settings.mcp_id api_key = get_api_key() if not api_key: raise UpstreamError("API key is not configured") headers = { "XBY-APIKEY": api_key, "func": tool_name, "mcpid": mcp_id, "Content-Type": "application/json", } t0 = time.time() try: resp = self._session.post( url=url, headers=headers, data=json.dumps(params), timeout=settings.timeout_seconds, ) ``` ### Technical Analysis The Pydantic configuration permits environment variables with the `XBY_GAOKAO_` prefix to override settings, including `base_url`. Consequently, `XBY_GAOKAO_BASE_URL` can replace the expected service endpoint. The HTTP client constructs its destination directly from this configurable value without validating the URL scheme or destination host. It then transmits the API key in the `XBY-APIKEY` header and sends the complete tool parameters in the request body. Those parameters contain either a user-provided image URL or the full Base64-encoded image. There is no HTTPS-only enforcement, hostname allowlist, or redirect-origin validation. A malicious or mistakenly configured endpoint can therefore receive both the API credential and image input. ### Attack Path 1. An attacker with influence over deployment configuration, process environment variables, or the loaded `.env` configuration sets `XBY_GAOKAO_BASE_URL` to an attack ...[truncated 1154 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove runtime configurability of the production API origin unless it is operationally required. 2. If configuration is required, parse the URL and enforce: - The `https` scheme. - An exact hostname allowlist, such as `mcp.xiaobenyang.com`. - An expected port and path. - Rejection of embedded credentials, fragments, and unexpected URL components. 3. Disable redirects for credential-bearing requests or manually validate every redirect destination before forwarding sensitive headers. 4. Never forward `XBY-APIKEY` across origins. 5. Separate test and production clients so test endpoint overrides cannot be enabled accidentally in production. 6. Add automated tests proving that HTTP endpoints, unapproved hosts, malformed URLs, and cross-origin redirects are rejected. 7. Rotate the API key if requests may already have been sent to an untrusted endpoint. ]]>
