T09 · Insecure Skill Coding Practices
- Location
scripts/config.py:9- Finding
API Key Can Be Redirected to an Attacker-Controlled Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/config.py:9-17andscripts/call_api.py:51-68
Vulnerability Type: Unvalidated security-sensitive endpoint configuration
Risk Level: HighVulnerable code in
scripts/config.py: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 = ""Vulnerable code in
scripts/call_api.py: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 working-directory.envfile. The HTTP client then constructs its destination directly from this configurable value and automatically attaches the user's API key in theXBY-APIKEYheader.No validation ensures that the final URL uses HTTPS or belongs to the expected
mcp.xiaobenyang.comhost. Consequently, an attacker who can influence the process environment or place a crafted.envfile in the working directory can redirect authenticated requests to a server under the attacker's control.Attack Path
- The attacker gains the ability to set an environment variable for the Skill process or place a
.envfile in its working directory.
...[truncated 1011 chars]
- The attacker gains the ability to set an environment variable for the Skill process or place a
- Remediation
View remediation
Remediation Suggestions
- Make the API origin a non-overridable constant when arbitrary endpoints are not a supported requirement.
- If endpoint configuration is required, parse the URL and enforce an explicit allowlist containing only
https://mcp.xiaobenyang.com. - Reject non-HTTPS schemes, embedded credentials, unexpected ports, malformed hosts, and deceptive subdomains.
- Disable redirects for authenticated requests or validate every redirect destination before forwarding sensitive headers.
- Do not load security-sensitive endpoint configuration from an untrusted working-directory
.envfile. - Separate credentials by endpoint so that a credential issued for the production service is never attached to a different origin.
- Add automated tests proving that HTTP URLs and unapproved domains are rejected before any network request is sent.
