T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:86- Finding
Bearer API Key Can Be Redirected to an Arbitrary Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:86-100, 128-143; duplicated inscripts/videogen.py:86-100, 128-143
Vulnerability Type: Unrestricted authenticated endpoint configuration
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 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
Both API clients accept a base URL from the
--base-urlcommand-line option, theAI_HIVE_BASE_URLenvironment variable, or the local configuration file. The value is used without validating its scheme or hostname.The client subsequently sends the real AI-HIVE API key in the
Authorization: Bearerheader to every URL constructed from that configurable base URL. Consequently, an attacker who can influence a command, environment variable, or configuration file can redirect authenticated requests to an attacker-controlled server.The implementation does not require HTTPS, restrict the destination to an approved AI-HIVE hostname, or request confirmation before transmitting the credential to a custom endpoint. The same vulnerable implementation is present in both im ...[truncated 1290 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove runtime base-URL overrides unless they are required for a documented development workflow.
- Enforce HTTPS and reject URLs containing user information, fragments, unexpected ports, or non-network schemes.
- Maintain an explicit allowlist of approved API hostnames and verify the normalized hostname before adding the bearer header.
- Never send the production API key to a custom endpoint. If custom endpoints are supported, require a separate credential.
- Reject redirects to unapproved hosts, or disable redirects for authenticated API requests.
- Treat environment and configuration values as untrusted input and display the validated destination before authenticated operations.
- Add tests covering HTTP URLs, lookalike domains, subdomain confusion, embedded credentials, redirects, and malicious configuration values.
- Apply the same remediation to
scripts/videogen.py, which duplicates the vulnerable client implementation.
