T09 · Insecure Skill Coding Practices
- Location
scripts/videogen.py:84- Finding
API Credential Disclosure Through an Unrestricted Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/videogen.py, lines 84–96; authentication and request sink at lines 133–148
Vulnerability Type: Unvalidated destination 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_URLThe resulting URL is subsequently used with the API credential:
python 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 application accepts an API base URL from a command-line argument, the
AI_HIVE_BASE_URLenvironment variable, or the local configuration file. It does not validate the URL scheme or verify that the destination belongs to an approved AI Hive host.AiHiveClientthen attaches the AI Hive API key as a bearer token to every request sent to the selected destination. Consequently, control over any base URL input is equivalent to control over the destination to which the credential is disclosed.TLS certificate validation by
requestsdoes not prevent this issue because an attacker can operate a valid HTTPS domain with a legitimate certificate. The vulnerability does not require interception of traffic; the program intentionally sends the authorization header to the configu ...[truncated 1206 chars]- Remediation
View remediation
Remediation Suggestions
- Require
httpsfor authenticated endpoints and reject URLs containing user information, fragments, or unexpected ports. - Use an explicit allowlist of trusted API hosts, such as the documented AI Hive hostname.
- Do not attach an AI Hive credential when the destination is outside the allowlist.
- If custom endpoints are a required feature, require explicit interactive confirmation and a separate credential intended for that endpoint.
- Normalize and validate the hostname before comparison, accounting for case, trailing dots, internationalized domains, and deceptive subdomains.
- Consider removing base URL overrides from normal production use or restricting them to a clearly marked development mode.
- Add tests confirming that HTTP URLs, lookalike domains, subdomains, and unapproved HTTPS hosts are rejected.
An example defensive policy is:
python from urllib.parse import urlparse ALLOWED_API_HOSTS = {"ai-hive.iclip.cn"} def validate_base_url(value): parsed = urlparse(value) if parsed.scheme != "https": raise SystemExit("The API Base URL must use HTTPS") if parsed.hostname not in ALLOWED_API_HOSTS: raise SystemExit("The API Base URL host is not trusted") if parsed.username or parsed.password or parsed.fragment: raise SystemExit("The API Base URL contains prohibited components") return value.rstrip("/")- Require
