T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:68- Finding
Bearer API Credential Can Be Redirected to an Arbitrary Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:68-76andscripts/imagegen.py:105-123
Vulnerability Type: Unrestricted credential forwarding to a configurable endpoint
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 __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
The API base URL may be supplied through a command-line option, the
AI_HIVE_BASE_URLenvironment variable, or the user-writable configuration file. The value is accepted without validating its scheme, hostname, port, or relationship to the expected AI Hive service.The HTTP client unconditionally attaches the AI Hive bearer credential to every request constructed from that configurable base URL. Consequently, any party able to influence the process environment, command invocation, or
base_urlconfiguration can redirect authenticated requests to a server under their control.TLS certificate validation by
requestsdoes not prevent this attack when the destination is an attacker-owned HTTPS server with a valid certificate. The flaw is therefore an endpoint trust failure rather ...[truncated 1228 chars]- Remediation
View remediation
Remediation Suggestions
- Allowlist the expected HTTPS origin, including the exact hostname and permitted port.
- Reject non-HTTPS URLs and URLs containing user information, fragments, unexpected ports, or untrusted hostnames.
- Do not attach the AI Hive bearer credential unless the final request destination matches the trusted allowlist.
- Treat custom API endpoints as an exceptional development feature requiring an explicit, high-friction opt-in.
- Display a warning and require confirmation before sending credentials to any non-default endpoint.
- Validate redirects or disable them for authenticated API requests so a trusted endpoint cannot redirect the credential-bearing request to another origin.
- Store custom endpoint configuration separately from credentials and verify configuration-file ownership and permissions before trusting it.
- Add automated tests proving that credentials are never sent to untrusted schemes, hosts, ports, or redirect destinations.
