T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:94- Finding
AI-HIVE API Key Disclosure Through an Unrestricted Base URL in the Image Generation Client
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py, lines 94-101 and 125-143
Vulnerability Type: Credential disclosure through an attacker-controlled API endpoint
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 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 )Technical Analysis
The client resolves its API base URL from the
--base-urlargument, theAI_HIVE_BASE_URLenvironment variable, or the persistent configuration file without validating the URL scheme or destination host. It then attaches the AI-HIVE bearer credential to every request made through that base URL.Consequently, an attacker who can influence a generated command, process environment, or
~/.ai-hive/config.jsoncan redirect authenticated requests to an attacker-controlled server. The code does not require HTTPS, restrict the destination to the documented AI-HIVE host, or request confirmation before forwarding the credential to a different origin.Attack Path
- The victim has a valid API key in
AI_HIVE_API_KEYor~/.ai-hive/config.json. - An attacker causes the victim to set `AI_ ...[truncated 928 chars]
- The victim has a valid API key in
- Remediation
View remediation
Remediation Suggestions
- Restrict authenticated requests to an explicit allowlist of trusted AI-HIVE origins, using exact normalized scheme, hostname, and port comparisons.
- Require HTTPS and reject plaintext HTTP, URL user-information components, unsupported schemes, malformed URLs, and unexpected ports.
- If custom endpoints are legitimately required, do not send the production AI-HIVE credential to them by default. Require a separate credential and an explicit interactive confirmation that names the destination origin.
- Do not persist an arbitrary base URL in the same configuration record as the API key.
- Normalize URLs with a standard URL parser rather than relying on
rstrip("/"). - Disable automatic redirects for authenticated requests or verify every redirect destination before retaining the
Authorizationheader. - Add tests covering malicious environment variables, HTTP endpoints, look-alike domains, user-information URLs, and cross-origin redirects.
- Advise affected users to rotate their API keys if they previously used an untrusted custom base URL.
