T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/call_api.py:56
- Finding
- API Credential and OCR Data Can Be Sent to a Configurable Untrusted Endpoint## Vulnerability Details **File Location**: `scripts/config.py:11-21`, `scripts/call_api.py:56-78` **Vulnerability Type**: Unvalidated configurable API destination **Risk Level**: High ### Vulnerable Code `scripts/config.py:11-21`: ```python 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 = "" ``` `scripts/call_api.py:56-78`: ```python 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; call set_api_key() first") headers = { "XBY-APIKEY": api_key, "func": tool_name, "mcpid": mcp_id, "Content-Type": "application/json", } # data = {k: str(v) if v is not None else "" for k, v in params.items()} t0 = time.time() try: resp = self._session.post( url=url, headers=headers, data=json.dumps(params), timeout=settings.timeout_seconds, ) ``` ### Technical Analysis The Pydantic settings configuration uses the `XBY_GAOKAO_` environment prefix. Consequently, the `base_url` field can be overridden through `XBY_GAOKAO_BASE_URL` or a corresponding settings source. The client does not validate the resulting URL against an approved origin and does not require the configured destination to use HTTPS. It constructs the API URL directly from this configurable value and sends the API credential in the `XBY-APIKEY` header. The request body also contains the user-provided image URL or Base64-encoded image. An attacker who can influence the process environment or relevant configuration can redirect requests to an attacker-controlled server. This is a credential and application-data exfiltration issue rather than server-side reque ...[truncated 1373 chars]
- Remediation
- ## Remediation Suggestions 1. Remove runtime configurability for the production API origin where it is not required. 2. Validate `settings.base_url` before every request using a parsed URL rather than string-prefix checks. 3. Require the `https` scheme and reject URLs containing user information, unexpected ports, fragments, or unapproved hostnames. 4. Maintain an explicit allowlist containing the exact expected origin, such as `https://mcp.xiaobenyang.com`. 5. Resolve and validate redirect destinations, or disable automatic redirects for authenticated requests. 6. Never forward `XBY-APIKEY` to a destination whose scheme, hostname, and port do not exactly match the approved API origin. 7. If endpoint overrides are needed for development, gate them behind an explicit development mode and use separate non-production credentials. 8. Add tests confirming that HTTP URLs, lookalike domains, embedded credentials, unexpected ports, and attacker-controlled environment overrides are rejected.
