T09 · Insecure Skill Coding Practices
- Location
scripts/config.py:12- Finding
Configurable API Endpoint Can Expose Credentials and User Content
- Content
View full analysis
Vulnerability Details
File Location:
scripts/config.py:12-18,scripts/call_api.py:49-71
Vulnerability Type: Unvalidated configurable endpoint used for sensitive outbound requests
Risk Level: MediumVulnerable Code
python model_config = SettingsConfigDict( env_prefix="XBY_GAOKAO_", env_file=".env", env_file_encoding="utf-8", extra="ignore", ) # API配置 base_url: str = "https://mcp.xiaobenyang.com" mcp_id: str = "1820705335657482" api_key: str = ""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密钥未设置,请先调用 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
The Pydantic settings configuration permits fields to be overridden using environment variables with the
XBY_GAOKAO_prefix and values from.env. Consequently,XBY_GAOKAO_BASE_URLcan replace the intended API origin.XiaoBenYangClient.call_tool()constructs the request URL directly fromsettings.base_urlwithout validating the URL scheme or destination hostname. It then sends the API key in theXBY-APIKEYheader and sends the complete tool parameters—including user-provided Markdown—in the request body.An attacker capable of altering the process environment or the applicable
.envconfiguration can therefore redirect requests to an attacker-controlled endpoint. The implementation does not enforce HTTPS, pin the approved hostname, or explicitly disable redirects.Attack Path
- The attacker gain ...[truncated 1159 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove runtime configurability of the production API origin if alternate endpoints are not required.
- Otherwise, parse the configured URL and require:
- The
httpsscheme. - An exact approved hostname, such as
mcp.xiaobenyang.com. - An approved port.
- No embedded username or password.
- The
- Reject IP literals, malformed URLs, and unapproved subdomains.
- Disable automatic redirects for requests carrying credentials, or validate the scheme and hostname of every redirect target before following it.
- Separate credential-bearing transport code from general configurable HTTP clients.
- Document that submitted Markdown is transmitted to the external service and obtain appropriate user consent for sensitive content.
- Add tests proving that environment variables cannot redirect credential-bearing requests to HTTP or an unapproved hostname.
