T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
Bearer API Key Disclosure Through an Unrestricted Custom API Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:91-99, 130-143;scripts/videogen.py:91-99, 130-143
Vulnerability Type: Unrestricted credential forwarding to a configurable endpoint
Risk Level: HighVulnerable Code
The following logic appears in both affected scripts:
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_URLThe selected URL is subsequently used with the bearer credential:
python 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
Both scripts allow the API base URL to be supplied through a command-line argument, the
AI_HIVE_BASE_URLenvironment variable, or~/.ai-hive/config.json. The value is accepted without enforcing HTTPS, verifying the destination hostname, or requiring confirmation for a nonstandard endpoint.AiHiveClientthen attaches the AI-HIVE API key to every request as anAuthorization: Bearerheader. Consequently, changing the base URL redirects authenticated requests and discloses the credential to the selected server. Generation prompts, task identifiers, pricing data, and media-upload metadata may also be exposed.Attack Path
- An attacker ...[truncated 1257 chars]
- Remediation
View remediation
Remediation Suggestions
- Restrict authenticated requests to an explicit allowlist, with
ai-hive.iclip.cnas the default permitted hostname. - Parse endpoints with
urllib.parse.urlparseand reject URLs that do not use HTTPS. - Reject URLs containing embedded credentials, unexpected ports, fragments, or malformed hostnames.
- Do not forward an AI-HIVE credential to custom endpoints. Require a separate credential when custom API-compatible servers are supported.
- Require an explicit interactive confirmation before using any nonstandard endpoint and display the exact destination hostname.
- Protect the configuration file against unauthorized modification and warn when its ownership or permissions are unsafe.
- Apply the same validation in both
imagegen.pyandvideogen.py, preferably through a shared, centrally tested configuration module. - Add automated tests confirming that HTTP endpoints and unapproved hosts are rejected before any authenticated request is made.
- Restrict authenticated requests to an explicit allowlist, with
