T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:92- Finding
API Key Disclosure Through an Arbitrary Base URL in the Image Client
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py, lines 92–99 and 130–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 self.headers = { "Authorization": f"Bearer {config.api_key}", "Content-Type": "application/json", }python 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 client accepts its API base URL from a command-line option, the
AI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. It does not require HTTPS, validate the hostname, restrict ports, or warn when the endpoint differs from the official AI-HIVE service.The client subsequently attaches the AI-HIVE bearer credential to every API request made through
_request(). Consequently, a maliciously supplied base URL causes the legitimate API key to be transmitted to an attacker-controlled server. Supporting arbitrary credential-bearing endpoints is not required for the documented production workflow and violates least-destination principles for secrets.Attack Path
- An attacker persuades the user to run the client with a malicious
--base-url, modifiesAI_HIVE_BASE_URL, or alters~/.ai-hive/config.json. - The user invokes an ordinary command such as model listing, image generation, task polling, or media upload.
_resolve_base_url()...[truncated 536 chars]
- An attacker persuades the user to run the client with a malicious
- Remediation
View remediation
Remediation Suggestions
- Allow authenticated requests only to an explicit allowlist of official AI-HIVE API hostnames.
- Require HTTPS and reject URLs containing user information, unexpected ports, fragments, or non-HTTP schemes.
- Remove production support for arbitrary base URLs unless it is operationally necessary.
- If custom endpoints are needed for development, require an explicit unsafe-development option and a separate non-production credential.
- Disable cross-origin redirects for authenticated requests or validate every redirect destination before forwarding credentials.
- Display a clear confirmation warning before sending a credential to any non-default destination.
- Protect the configuration file from unauthorized modification in addition to retaining its existing
0600permissions.
