T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:94- Finding
API Key Disclosure Through a User-Configurable API Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:94-99, 128-143; equivalent implementation inscripts/videogen.py:94-99, 128-143
Vulnerability Type: Arbitrary credential transmission caused by insufficient endpoint validation
Risk Level: MediumVulnerable 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 API base URL may be supplied through a command-line argument, the
AI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. The value is accepted without verifying its scheme or hostname.The client subsequently attaches the AI-HIVE bearer token to every request made against that endpoint. Consequently, an arbitrary endpoint configured through any of these channels receives the user's API key. The implementation does not enforce HTTPS, restrict destinations to the documented AI-HIVE domain, or warn the user before sending credentials to a nonstandard destination.
The same vulnerable implementation is present in both
imagegen.pyandvideogen.py.Attack Path
- An attacker modifies the v ...[truncated 1095 chars]
- Remediation
View remediation
Remediation Suggestions
- Restrict normal API operations to the documented
https://ai-hive.iclip.cnhostname. - Reject non-HTTPS URLs and URLs containing embedded credentials, unexpected ports, fragments, or unapproved hostnames.
- If custom endpoints are a legitimate requirement, require an explicit opt-in flag and interactive confirmation before transmitting a credential.
- Use separate, endpoint-specific credentials instead of reusing the production AI-HIVE key with custom servers.
- Validate the ownership and permissions of
~/.ai-hive/config.jsonbefore trusting its contents. - Display the selected endpoint before authenticated operations without displaying the API key.
- Apply the same endpoint-validation changes to both
scripts/imagegen.pyandscripts/videogen.py. - Add automated tests confirming that HTTP endpoints, lookalike domains, malformed URLs, and unapproved hosts are rejected.
- Restrict normal API operations to the documented
