T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
Configurable API Origin Can Expose the Bearer API Key
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:91-100, 124-143; identical implementation inscripts/videogen.py:91-100, 124-143
Vulnerability Type: Unrestricted authenticated API 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 class AiHiveClient: """AI Hive OpenAPI HTTP client.""" 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 )The same scripts expose the endpoint through the
--base-urlcommand-line argument and theAI_HIVE_BASE_URLenvironment variable.Technical Analysis
The API origin is accepted from command-line input, an environment variable, or the local configuration file without validating its scheme or hostname. The client then attaches the AI-HIVE bearer credential to every request constructed from that origin.
Consequently, an attacker who can influence the invocation environment, command arguments, or configuration can redirect authenticated requests to an attacker-controlled server. An
http://endpoint would additionally transmit the bearer credent ...[truncated 1445 chars]- Remediation
View remediation
Remediation Suggestions
- Enforce HTTPS and reject every endpoint using another scheme.
- Use a strict hostname allowlist, with
ai-hive.iclip.cnas the approved production host. - Do not send the
Authorizationheader when the request origin differs from the approved API origin. - Disable cross-origin redirects for authenticated requests, or validate every redirect target before following it.
- Reject URLs containing embedded credentials, malformed hosts, ambiguous Unicode hostnames, unexpected ports, fragments, or non-API paths.
- If custom endpoints are required for development, place the capability behind an explicit development option and display a high-friction warning before transmitting credentials.
- Store development credentials separately and use limited-scope keys for non-production endpoints.
- Apply the same remediation to
scripts/videogen.py, which contains the identical client implementation. - Add tests confirming that HTTP endpoints, unapproved hosts, cross-origin redirects, and malformed URLs are rejected before any authenticated network request occurs.
