T09 · Insecure Skill Coding Practices
- Location
scripts/call_api.py:48- Finding
API credential disclosure through a configurable upstream endpoint
- Content
View full analysis
HttpResult: """调用小笨羊MCP工具""" 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 upstream `base_url` is a security-sensitive setting because every API request sends the user's `XBY-APIKEY` credential to that destination. Pydantic Settings permits this value to be overridden through the `XBY_GAOKAO_BASE_URL` environment variable or the working-directory `.env` file. The request logic constructs a URL directly from this configurable value and attaches the API key without validating the URL scheme, hostname, port, or origin. Consequently, an attacker who can influence the process environment or place a crafted `.env` file in the working directory can redirect authenticated requests to an attacker-controlled server. TLS does not prevent this attack if the subst ...[truncated 1742 chars]- Remediation
View remediation
