T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:98- Finding
API Credential Disclosure Through an Unrestricted Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py, lines 98–106, 118–130, 640–646, and 819–823
Vulnerability Type: User-controlled API endpoint combined with automatic bearer-token transmission
Risk Level: HighVulnerable Code
python def _resolve_base_url(self, cli_url): if cli_url: return cli_url.rstrip("/") env_url = os.environ.get("AI_HIVE_BASE_URL") if env_url: return env_url.rstrip("/") file_config = self._read_config_file() if file_config.get("base_url"): return file_config["base_url"].rstrip("/") return DEFAULT_BASE_URLpython class AiHiveClient: """AI Hive OpenAPI HTTP client.""" def __init__(self, config): self.config = config self.base = config.base_url self.headers = { "Authorization": f"Bearer {config.api_key}", "Content-Type": "application/json", } def _url(self, path): return f"{self.base}/openapi/v1/{path}" def _request(self, method, url, **kwargs): self.config.log(f"{method} {url}") try: resp = requests.request( method, url, headers=self.headers, timeout=DEFAULT_TIMEOUT, **kwargs ) except requests.exceptions.ConnectionError as e: raise SystemExit( f"Unable to connect to API server: {url}\n" f"Reason: {e}" ) except requests.exceptions.Timeout: raise SystemExit(f"API request timed out: {url}") except requests.exceptions.RequestException as e: raise SystemExit(f"Network request failed: {e}") if not resp.ok: try: detail = resp.json() except ValueError: detail = resp.text raise SystemExit( f"API request failed ({resp.s ...[truncated 2244 chars]- Remediation
View remediation
Remediation Suggestions
- Default to an immutable allowlist containing only the official HTTPS API origin.
- Parse base URLs with
urllib.parse.urlparseand reject:- Non-HTTPS schemes
- URLs containing user information
- Unexpected ports
- Hosts outside the approved allowlist
- Never send an AI Hive API key to a custom host. If custom endpoints are required, use separate credentials scoped to those endpoints.
- Require explicit, high-friction confirmation before enabling a custom endpoint.
- Reject custom base URLs supplied through ambient environment variables in privileged or automated execution contexts.
- Revalidate the destination after redirects, or disable redirects for authenticated API requests.
- Document immediate key revocation and rotation procedures if an untrusted endpoint was previously configured.
