T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:94- Finding
API Credential Disclosure Through an Unrestricted Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py, lines 94–99 and 128–143
Vulnerability Type: Unrestricted API endpoint override with automatic bearer-token forwarding
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 accepts an API base URL from the
--base-urlcommand-line option, theAI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. It does not validate the URL scheme, hostname, port, or destination.Every API request then unconditionally includes the user's AI-HIVE API key in the
Authorizationheader. Consequently, redirecting the base URL to an attacker-controlled endpoint causes the application to disclose the bearer credential. This is a credential-forwarding vulnerability rather than intended credential use because the token is documented and provisioned for AI-HIVE, while the code allows it to be transmitted to an unrelated host.Attack Path
- An attacker convinces a user or agent to execute
imagegen.pywith a malicious--base-url, setAI_HIVE_BASE_URLto an attacker-controlled URL, or modify `~/.ai-hive/co ...[truncated 1000 chars]
- An attacker convinces a user or agent to execute
- Remediation
View remediation
Remediation Suggestions
- Restrict authenticated API requests to an explicit allowlist of trusted HTTPS hosts, with
ai-hive.iclip.cnas the default trusted destination. - Parse URLs with a standard URL parser and reject:
- Non-HTTPS schemes
- Embedded user information
- Unexpected hostnames
- Unapproved ports
- Malformed or ambiguous hostnames
- Do not attach
Authorizationwhen the destination origin differs from the approved API origin. - Disable automatic cross-origin redirects for authenticated requests, or validate the destination again before following each redirect.
- If custom deployments are a required feature, use separate credentials scoped to each configured origin and require explicit user confirmation before storing or using them.
- Add automated tests confirming that credentials are never transmitted to an unapproved scheme, host, port, or redirect destination.
- Advise affected users to revoke and rotate API keys if they have used an untrusted custom base URL.
- Restrict authenticated API requests to an explicit allowlist of trusted HTTPS hosts, with
