T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
Bearer API Credential Can Be Redirected to an Arbitrary Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:91-100, 128-143;scripts/videogen.py:91-100, 128-143
Vulnerability Type: Unrestricted API endpoint override leading to credential disclosure
Risk Level: MediumVulnerable Code
The same implementation appears in both
scripts/imagegen.pyandscripts/videogen.py: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 can be supplied through a command-line argument, the
AI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. The value is accepted without validating its scheme or hostname.The HTTP client subsequently adds the user's bearer API key to every request sent to the configured base URL. Consequently, an attacker-controlled endpoint receives the
Authorizationheader. The implementation also accepts unencrypted HTTP URLs, which can expose credentials to network interception.This is a credential-forwarding vulnerability caused by combining an unrestricted destination override with automatic attachment of sensitive authentication mate ...[truncated 1725 chars]
- Remediation
View remediation
Remediation Suggestions
- Permit the official
https://ai-hive.iclip.cnorigin by default and validate the parsed hostname, scheme, and effective port before attaching credentials. - Reject plaintext HTTP endpoints whenever an API key is present.
- If custom endpoints are required for development, require an explicit option such as
--allow-custom-endpoint, display the destination, and request confirmation before transmitting credentials. - Maintain separate authentication policies for official and custom origins. Do not automatically forward the production API key to nonstandard hosts.
- Avoid following redirects that cross origins while retaining the
Authorizationheader. - Validate upload URLs returned by the API against documented object-storage schemes and host policies before uploading media.
- Apply the same centralized, hardened HTTP client to both scripts to prevent security fixes from diverging.
- Add tests covering malicious base URLs, non-HTTPS URLs, deceptive subdomains, embedded credentials, unusual ports, and cross-origin redirects.
- Permit the official
