T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
API Credentials Can Be Redirected to an Attacker-Controlled Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:91-99, 130-143; duplicated inscripts/videogen.py:91-99, 130-143
Vulnerability Type: Arbitrary credential destination
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 class AiHiveClient: 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 scripts accept the API base URL from a command-line argument, the
AI_HIVE_BASE_URLenvironment variable, or the local configuration file. They perform no URL-scheme validation, trusted-host verification, or origin binding between the API key and the endpoint.The client unconditionally attaches the AI-HIVE bearer credential to every request constructed from that configurable base URL. Consequently, a malicious environment variable, command-line value, or modified
~/.ai-hive/config.jsoncan redirect the credential to an arbitrary HTTP or HTTPS server.HTTPS certificate verification by
requestsdoes not address this issue when the attacker controls a valid HTTPS domain. Plaint ...[truncated 1170 chars]- Remediation
View remediation
Remediation Suggestions
- Require an
httpsURL scheme for all credential-bearing API requests. - Bind AI-HIVE credentials to the exact trusted AI-HIVE hostname.
- Reject URLs containing user information, unexpected ports, fragments, or non-HTTPS schemes.
- If custom enterprise gateways are required, maintain an explicit administrator-controlled hostname allowlist.
- Require separate credentials for custom gateways rather than forwarding the AI-HIVE key.
- Display the effective credential destination and require explicit confirmation before first use of a non-default endpoint.
- Protect the configuration directory as well as the file, and reject configuration files not owned by the current user.
- Apply the same correction to both
scripts/imagegen.pyandscripts/videogen.py.
- Require an
