T09 · Insecure Skill Coding Practices
- Location
scripts/xiehouyu_query.py:24- Finding
Unvalidated API Base URL Allows Credential and Query Exfiltration
- Content
View full analysis
dict[str, Any]: url = f"{API_BASE_URL}{API_PATH_MAP[command]}?{urllib.parse.urlencode({**params, 'appkey': appkey})}" try: with urllib.request.urlopen(url, timeout=15) as response: return json.loads(response.read().decode("utf-8")) except urllib.error.HTTPError as exc: return {"code": exc.code, "message": f"接口请求失败: HTTP {exc.code}", "data": ""} except urllib.error.URLError as exc: return {"code": 500, "message": f"网络请求失败: {exc.reason}", "data": ""} except Exception as exc: return {"code": 500, "message": f"请求异常: {exc}", "data": ""} ``` ### Technical Analysis The API base URL is read from the undocumented `JIKE_API_BASE_URL` environment variable without validating its scheme or hostname. The resulting value is used directly as the destination for an outbound request. The request places the AppKey in the URL query string alongside user-controlled query parameters. Consequently, a party capable of influencing the process environment can redirect requests to an attacker-controlled endpoint. Because HTTPS is not enforced, the override can also select a plaintext HTTP endpoint. Including credentials in a URL additionally increases exposure through HTTP server logs, reverse-proxy logs, monitoring systems, and other infrastructure that records complete request URLs. This issue requires the attacker to control or influence the environment in which the skill process starts. It does not independently provide local code execution or privilege escalation. ### Attack Path 1. The vict ...[truncated 1166 chars]- Remediation
View remediation
str: parsed = urlparse(value) if ( parsed.scheme != "https" or parsed.hostname not in ALLOWED_API_HOSTS or parsed.username is not None or parsed.password is not None or parsed.fragment ): raise ValueError("Invalid or unapproved API base URL") return value.rstrip("/") API_BASE_URL = validate_api_base_url( os.environ.get("JIKE_API_BASE_URL", DEFAULT_API_BASE_URL) ) ``` ]]>
