T09 · Insecure Skill Coding Practices
- Location
scripts/config.py:9- Finding
API Key and Tool Data Can Be Redirected to an Attacker-Controlled Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/config.py:9-19;scripts/call_api.py:53-75
Vulnerability Type: Configurable credential-exfiltration destination
Risk Level: HighVulnerable Code
python class Settings(BaseSettings): """小笨羊高考Skill配置""" 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 def call_tool( self, mcp_id: str, tool_name: str, params: dict[str, Any], ) -> 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", } t0 = time.time() try: resp = self._session.post( url=url, headers=headers, data=json.dumps(params), timeout=settings.timeout_seconds, )Technical Analysis
The
SettingsConfigDictconfiguration permits environment variables beginning withXBY_GAOKAO_to override settings fields. Consequently,XBY_GAOKAO_BASE_URLcan replace the intendedhttps://mcp.xiaobenyang.comdestination.The HTTP client constructs the request URL directly from this configurable value and sends the user's API key in the
XBY-APIKEYheader. It does not validate the URL scheme, compare the hostname against an allowlist, or otherwise bind credential transmission to the intended service. The session also supports both HTTP and HTTPS adapters, so a substituted plaintext HTTP des ...[truncated 1536 chars]- Remediation
View remediation
Remediation Suggestions
- Do not permit the credential destination to be overridden in production. Use a fixed constant for the official API origin.
- If endpoint configurability is required for development, enforce an explicit allowlist of trusted hostnames.
- Require HTTPS and reject URLs with any other scheme before constructing a request.
- Normalize and validate the hostname, port, user-information component, and resolved destination to prevent parser ambiguity and DNS-based bypasses.
- Disable cross-origin redirects for authenticated requests, or remove the
XBY-APIKEYheader whenever the origin changes. - Separate development and production configuration so test endpoint support cannot silently operate with production credentials.
- Add automated tests confirming that HTTP URLs, unapproved hosts, embedded credentials, and cross-origin redirects are rejected.
