T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:89- Finding
Bearer API Key Disclosure Through an Unrestricted Base URL Override in the Image Generator
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:89-99, 132-143, 587
Vulnerability Type: Unvalidated API endpoint override causing credential disclosure
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 self.headers = { "Authorization": f"Bearer {config.api_key}", "Content-Type": "application/json", }python 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 origin can be replaced through the
--base-urlargument, theAI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. The supplied value is accepted without validating its scheme, hostname, port, or origin.The same client automatically attaches the AI-HIVE bearer API key to every request made against the resulting URL. Consequently, an attacker-controlled endpoint receives the API key in the
Authorizationheader. The implementation also accepts plain HTTP URLs, allowing the credential and request contents to be transmitted without transport encryption.A configurable API endpoint may be useful for development, but automatically forwarding a production credential to any arbitrary origin exceeds the minimum privileges required for the declared image-generation functionality.
Attack Path
- An attacker convinces the user to run the image generator with a malicious
--base-url, modifiesAI_HIVE_BASE_URL, or alters thebase_url...[truncated 1062 chars]
- An attacker convinces the user to run the image generator with a malicious
- Remediation
View remediation
Remediation Suggestions
- Restrict authenticated requests to an explicit HTTPS hostname allowlist, with
ai-hive.iclip.cnas the default permitted origin. - Parse the URL with a standard URL parser and reject non-HTTPS schemes, embedded credentials, unexpected ports, fragments, malformed hosts, and ambiguous hostnames.
- Disable cross-origin redirects for authenticated requests, or validate every redirect target before forwarding the
Authorizationheader. - Do not send the production API key to custom endpoints. If custom development endpoints are necessary, require a separate credential and an explicit high-friction opt-in.
- Ignore or reject untrusted
AI_HIVE_BASE_URLvalues in normal production operation. - Validate the configuration file owner and permissions before reading credentials or endpoint settings.
- Add automated tests proving that HTTP URLs, unknown hosts, and redirects to unknown origins are rejected.
- Restrict authenticated requests to an explicit HTTPS hostname allowlist, with
