T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
API Credential Disclosure Through an Unrestricted Custom Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:91-99, 130-143; identical implementation inscripts/videogen.py:91-99, 130-143
Vulnerability Type: Unvalidated destination used for authenticated HTTP requests
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 generation clients accept the API base URL from a command-line argument, the
AI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. The value is used without validating its scheme, hostname, port, or resolved IP address.The client constructs an
Authorization: Bearerheader containing the AI-HIVE API key and attaches it to every request sent to that base URL. Consequently, a modified environment or configuration can redirect an apparently legitimate command to an attacker-controlled server and disclose the credential. Plaintext HTTP is also accepted, allowing interception on an untrusted network.Redirect behavior is not explicitly disabled or constrained. Although common HTTP libraries may remove authorization ...[truncated 1555 chars]
- Remediation
View remediation
Remediation Suggestions
- Default to the fixed official endpoint and allow authenticated requests only to an explicit hostname allowlist, such as
ai-hive.iclip.cn. - Parse the URL with
urllib.parse.urlparseand require:- The
httpsscheme. - An approved hostname.
- An expected port or the default HTTPS port.
- No embedded username or password.
- The
- Resolve the hostname and reject loopback, private, link-local, multicast, reserved, and unspecified IP addresses.
- Disable automatic redirects for authenticated requests or validate every redirect destination before following it.
- Never forward the AI-HIVE bearer credential to a destination whose origin differs from the approved API origin.
- If custom compatible endpoints are a required feature, use a separate endpoint-specific credential and require an explicit interactive warning or trust configuration.
- Treat the configuration file as security-sensitive. Verify ownership and reject symlinks or files not owned by the current user before reading credentials and endpoint settings.
- Consolidate the duplicated HTTP client into one reviewed module so fixes apply consistently to image and video workflows.
- Default to the fixed official endpoint and allow authenticated requests only to an explicit hostname allowlist, such as
