T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
Bearer API key can be transmitted to an arbitrary or plaintext endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:91-99, 130-143, 587; equivalent code exists inscripts/videogen.py:91-99, 130-143, 587
Vulnerability Type: Unvalidated credential destination
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 )python parser.add_argument("--base-url", help=f"API Base URL (default {DEFAULT_BASE_URL})")Technical Analysis
The API base URL can come from the
--base-urlargument, theAI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. None of these sources is validated for an approved hostname or an HTTPS scheme.The client subsequently adds the AI-HIVE bearer credential to every request made through
_request. Consequently, an attacker who can influence one of the base URL configuration sources can redirect authenticated requests to a server under their control. A plaintext HTTP endpoint would also expose the credential to network interception.The same implementation is duplicated in both image and video generation scripts.
Attack Path
...[truncated 1125 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse the base URL with
urllib.parse.urlparseand reject all schemes except HTTPS. - Allowlist
ai-hive.iclip.cnas the credential-bearing destination by default. - If custom endpoints are required for development, require an explicit high-friction option and a separate credential rather than silently honoring environment or configuration changes.
- Reject URLs containing embedded credentials, unexpected ports, fragments, or ambiguous hostname encodings.
- Disable redirects for authenticated requests or validate every redirect destination before forwarding authorization headers.
- Do not persist arbitrary custom base URLs alongside production API keys.
- Apply the same validation centrally to both
imagegen.pyandvideogen.pyto prevent implementation drift. - Add tests covering HTTP URLs, attacker-controlled hosts, malformed URLs, cross-origin redirects, and approved production endpoints.
- Parse the base URL with
