T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/cortex.py:33
- Finding
- Authentication credentials can be transmitted to an arbitrary configurable endpoint<![CDATA[ ## Vulnerability Details **File Location**: `scripts/cortex.py:33-39, 68-84` **Vulnerability Type**: Credential exfiltration through an unrestricted endpoint override **Risk Level**: High ### Vulnerable Code ```python BASE = os.environ.get("HIQ_API_BASE", "https://x.hiqlcd.com") # 授权与查数同域,都在 BASE 上。 AUTH_BASE = os.environ.get("HIQ_AUTH_BASE", f"{BASE}/api/cortex") CRED_PATH = pathlib.Path(os.environ.get("HIQ_CRED_PATH", "")) if os.environ.get("HIQ_CRED_PATH") \ else pathlib.Path.home() / ".hiq" / "credentials.json" MCP_URL = f"{BASE}/api/cortex/mcp" SEARCH_URL = f"{BASE}/api/cortex/search" ``` ```python def _auth_header() -> dict: cred, kind = _credential() # 网关按凭据类型自动选校验方式,客户端只需二选一给对头。 return {"X-API-Key": cred} if kind == "api_key" else {"Authorization": f"Bearer {cred}"} # Cloudflare fronts the API and blocks the default `Python-urllib/3.x` agent with # error 1010 ("blocked based on your browser's signature"). Any conventional agent # string passes — this is not an auth issue and retrying without it will keep failing. _UA = "hiq-cortex-skill/1.0 (+https://www.hiqlcd.com)" def _post(url: str, data: bytes, headers: dict, timeout: int) -> str: # The gateway authenticates on X-API-Key only; Authorization: Bearer is rejected. req = urllib.request.Request( url, data=data, headers={**_auth_header(), "User-Agent": _UA, **headers} ) ``` ### Technical Analysis The `HIQ_API_BASE` environment variable controls both authenticated service destinations. `_post()` unconditionally adds either the `HIQ_API_KEY` value or the locally stored bearer token to requests sent to those destinations. The code does not verify that the resulting URL: - Uses HTTPS. - Has the exact expected hostname `x.hiqlcd.com`. - Has an approved port and path. - Has not been redirected to an untrusted origin. Consequently, a process environment modified by another launcher, CI configuration, shell profile, wrapper script, or compromised parent pr ...[truncated 1706 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove endpoint overrides from production builds unless they are strictly required for development. 2. Before attaching credentials, parse the destination with `urllib.parse.urlsplit()` and enforce: - Scheme exactly equal to `https`. - Hostname exactly equal to `x.hiqlcd.com`. - No embedded username or password. - No unexpected port. - An approved path prefix such as `/api/cortex/`. 3. Use separate allowlists for API and authentication endpoints. 4. Disable redirects for authenticated requests or validate every redirect target before forwarding credentials. 5. Never forward authentication headers across an origin change. 6. If development endpoints must remain configurable, require an explicit development mode and prevent production credentials from being used in that mode. 7. Update `SKILL.md` so its destination guarantees accurately match enforced behavior. ]]>
