T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:92- Finding
API Key Disclosure Through a Caller-Controlled Base URL in the Image Generation Client
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:92-99,scripts/imagegen.py:125-143
Vulnerability Type: Arbitrary credential destination
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 class AiHiveClient: """Encapsulates AI Hive OpenAPI HTTP calls.""" 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 loads an AI-HIVE API key from a command-line argument, environment variable, or persistent configuration file. Independently, it accepts the API base URL from
--base-url,AI_HIVE_BASE_URL, or the same configuration file without validating the URL scheme or destination hostname.AiHiveClientsubsequently attaches the bearer token to every request sent to the configured base URL. Consequently, an attacker who can influence the process environment, generated command line, or~/.ai-hive/config.jsoncan redirect authenticated requests to a server under their control. The implementation does not require HTTPS and does not restrict credential transmission to the intend ...[truncated 1032 chars]- Remediation
View remediation
Remediation Suggestions
- Restrict the Skill-specific client to the documented
https://ai-hive.iclip.cn/apiendpoint. - If custom endpoints are a legitimate requirement, normalize the URL and enforce an explicit allowlist of trusted HTTPS hostnames.
- Reject plaintext HTTP and URLs containing unexpected credentials, ports, schemes, or hostnames.
- Require an explicit interactive warning and confirmation before transmitting a credential to any non-default endpoint.
- Separate endpoint configuration from credential selection so a production AI-HIVE key cannot automatically be attached to an arbitrary host.
- Disable authorization forwarding across redirects, or reject cross-origin redirects before following them.
- Add tests verifying that malicious environment values and command-line URLs cannot receive the authorization header.
- Advise users to rotate their API key if it may already have been used with an untrusted base URL.
- Restrict the Skill-specific client to the documented
