T09 · Insecure Skill Coding Practices
- Location
scripts/call_api.py:56- Finding
API Credential and OCR Data Can Be Sent to a Configurable Untrusted Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/config.py:11-21,scripts/call_api.py:56-78
Vulnerability Type: Unvalidated configurable API destination
Risk Level: HighVulnerable 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, thebase_urlfield can be overridden throughXBY_GAOKAO_BASE_URLor 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-APIKEYheader. 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
View remediation
Remediation Suggestions
- Remove runtime configurability for the production API origin where it is not required.
- Validate
settings.base_urlbefore every request using a parsed URL rather than string-prefix checks. - Require the
httpsscheme and reject URLs containing user information, unexpected ports, fragments, or unapproved hostnames. - Maintain an explicit allowlist containing the exact expected origin, such as
https://mcp.xiaobenyang.com. - Resolve and validate redirect destinations, or disable automatic redirects for authenticated requests.
- Never forward
XBY-APIKEYto a destination whose scheme, hostname, and port do not exactly match the approved API origin. - If endpoint overrides are needed for development, gate them behind an explicit development mode and use separate non-production credentials.
- Add tests confirming that HTTP URLs, lookalike domains, embedded credentials, unexpected ports, and attacker-controlled environment overrides are rejected.
