T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:89- Finding
API Key Disclosure Through an Unrestricted API Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:89-99, 132-145, 585-587; mirrored inscripts/videogen.py:89-99, 132-145, 585-587
Vulnerability Type: Credential disclosure through an unvalidated endpoint override
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 _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 def add_common_args(parser): parser.add_argument("--api-key", help="AI Hive API Key (sk-api-*)") parser.add_argument("--base-url", help=f"API Base URL (default {DEFAULT_BASE_URL})") parser.add_argument("--verbose", action="store_true", help="Verbose logging")Technical Analysis
The client accepts an arbitrary base URL from a command-line argument, the
AI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. No validation requires HTTPS or restricts the destination to an approved AI-HIVE host.Every API request includes the following authorization header:
python self.headers = { "Authorization": f"Bearer {config.api_key}", "Content-Type": "application/json", }Consequently, an attacker who can influence the base URL can direct authenticated requests to an attacker-controlled service and capture the bearer API key. An HTTP URL can also expose the credential to network interception.
This is not covert exfiltration under the default configuration: the defaul ...[truncated 1071 chars]
- Remediation
View remediation
Remediation Suggestions
- Restrict normal operation to an explicit allowlist of approved API hosts.
- Require the URL scheme to be
https. - Reject URLs containing user information, fragments, unexpected ports, or non-approved hostnames.
- Treat custom endpoints as an advanced opt-in feature that does not automatically reuse the production API key.
- Require a separate credential for custom endpoints or display an explicit confirmation naming the destination receiving the key.
- Ignore
AI_HIVE_BASE_URLin privileged or automated execution contexts unless custom endpoints are explicitly enabled. - Validate the final URL immediately before each authenticated request to prevent malformed URL and redirect-related edge cases.
- Disable redirects for authenticated API requests or ensure authorization headers are never forwarded to a different origin.
- Apply the same correction to both
imagegen.pyandvideogen.py.
