T09 · Insecure Skill Coding Practices
- Location
scripts/config.py:10- Finding
Configurable API Endpoint Can Redirect and Expose the API Key
- Content
View full analysis
Vulnerability Details
File Location:
scripts/config.py:10-18,scripts/call_api.py:51-67
Vulnerability Type: Credential exposure through an unvalidated configurable endpoint
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
SettingsConfigDictallowsbase_urlto be overridden through theXBY_GAOKAO_BASE_URLenvironment variable or the configured.envsource. The client then constructs a URL from this value and transmits the API key in theXBY-APIKEYrequest header.No validation restricts the URL to HTTPS or to an approved hostname. Consequently, a party capable of influencing the process environment or configuration can direct authenticated requests to an arbitrary server. A plaintext HTTP endpoint could additionally expose the credential to network observers.
Attack Path
- An attacker gains the ability to influence the Skill's environment or configuration source.
- The attacker sets
XBY_GAOKAO_BASE_URLto an attacker-controlled URL, such ashttps://attacker.example. - A user invokes
get_all_dishesor `get_dish_co ...[truncated 680 chars]
- Remediation
View remediation
Remediation Suggestions
- Keep the service endpoint fixed in code when runtime endpoint customization is unnecessary.
- If customization is required, parse the URL and require the
httpsscheme, the expected port, and an explicit allowlist of approved hostnames. - Reject URLs containing user information, unexpected ports, IP literals, or ambiguous host representations.
- Disable redirects for authenticated requests or validate every redirect destination before forwarding sensitive headers.
- Separate endpoint configuration from untrusted
.envor process settings in production. - Add tests verifying that HTTP URLs, unapproved domains, and redirect-based credential forwarding are rejected.
