T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
Unrestricted API Base URL Can Expose the AI-HIVE Bearer Credential in the Image Generation Client
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py, lines 91-99 and 130-143
Vulnerability Type: Arbitrary authenticated API endpoint / credential disclosure
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 image generation client accepts its API base URL from the
--base-urlcommand-line option, theAI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. No validation restricts the URL scheme or destination host.The client then unconditionally attaches the AI-HIVE API key as an
Authorization: Bearerheader to requests constructed from that URL. Consequently, an attacker who can influence any accepted base URL source can redirect authenticated requests to an attacker-controlled endpoint. The implementation also permits anhttp://endpoint, which could expose the credential through network interception.This issue does not require arbitrary code execution. It exploits the trust placed in configuration data and the unconditional reuse of a sensitive production credential for an unverified origin.
Attack Path
- The victim ...[truncated 1298 chars]
- Remediation
View remediation
Remediation Suggestions
- Require HTTPS for every authenticated API endpoint and reject plaintext HTTP.
- Allowlist the expected API origin, such as
https://ai-hive.iclip.cn, before attaching the bearer credential. - Parse URLs with a standard URL parser and reject user information, fragments, malformed ports, unsupported schemes, and unexpected hosts.
- Do not send the production API credential to a custom host by default. If custom endpoints are needed for development, require a separate credential and an explicit opt-in.
- Treat the environment and configuration file as untrusted inputs. Validate the resolved URL regardless of its source.
- Consider storing only the API key in the configuration file and keeping the production endpoint fixed in code.
- Add tests confirming that HTTP URLs, lookalike domains, subdomain tricks, embedded credentials, and alternate ports are rejected.
- If exposure may already have occurred, revoke and rotate the affected API key and review account task and billing history.
