T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/config.py:10
- Finding
- Environment-Controlled API Endpoint Can Expose Credentials and Sensitive Documents<![CDATA[ ## Vulnerability Details **File Location**: `scripts/config.py:10-15`; data transmission occurs at `scripts/call_api.py:50-70` **Vulnerability Type**: Unvalidated configurable network destination **Risk Level**: Medium ### Complete Code Snippet ```python # scripts/config.py:10-15 model_config = SettingsConfigDict( env_prefix="XBY_GAOKAO_", env_file=".env", env_file_encoding="utf-8", extra="ignore", ) base_url: str = "https://mcp.xiaobenyang.com" ``` ```python # scripts/call_api.py:50-70 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密钥未设置,请先调用 set_api_key()") 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 `SettingsConfigDict` uses the `XBY_GAOKAO_` environment-variable prefix. Consequently, `XBY_GAOKAO_BASE_URL` can override the default `base_url`. The resulting value is used directly to construct the request destination without validating the scheme, hostname, port, or final origin. Every request to the configured destination contains the `XBY-APIKEY` credential. The body can also contain either a vehicle-license image URL or the complete Base64-encoded image. Vehicle licenses may disclose names, addresses, license-plate numbers, vehicle identification numbers, and engine numbers. Exploitation requires the attacker to influence the Skill process environment or its configuration. This is not a remote unauthenticated vulnerability by itself, but it becomes a credential and personal-data disclosure issue in environments where deployment variables, launch configuration, or `.env` settings are ...[truncated 968 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Pin the production API origin in code if endpoint customization is not required. - If customization is required, parse the URL and enforce an exact allowlist of approved HTTPS origins. - Reject non-HTTPS schemes, embedded credentials, unexpected ports, fragments, and malformed URLs. - Disable cross-origin redirects or verify the final redirect destination before forwarding credentials. - Do not attach the API-key header after a redirect to a different origin. - Separate development endpoint configuration from production configuration and require an explicit trusted deployment mode for overrides. - Add tests proving that HTTP URLs, attacker-controlled domains, user-info components, and cross-origin redirects are rejected. ]]>
