T09 · Insecure Skill Coding Practices
- Location
scripts/videogen.py:71- Finding
Unrestricted API Base URL Can Expose the Bearer API Key
- Content
View full analysis
Vulnerability Details
File Location:
scripts/videogen.py, lines 71-82, 118-130, and 586-587
Vulnerability Type: User-controlled authenticated API 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 )python def add_common_args(parser): parser.add_argument("--api-key", help="AI Hive API Key (sk-api-*)") parser.add_argument("--base-url", help=f"API Base URL (default {DEFAULT_BASE_URL})") parser.add_argument("--verbose", action="store_true", help="Verbose logging")Technical Analysis
The API base URL can be supplied through the
--base-urlcommand-line option, theAI_HIVE_BASE_URLenvironment variable, or thebase_urlproperty in the configuration file. The value is accepted without validating its scheme or hostname.AiHiveClientsubsequently attaches the AI Hive API key as a bearer token to every request sent through this base URL. Consequently, an attacker-controlled endpoint can receive the production credential. The implementation does not require HTTPS, restrict authenticated requ ...[truncated 1711 chars]- Remediation
View remediation
Remediation Suggestions
- Parse the endpoint with
urllib.parse.urlparseand reject malformed URLs, embedded credentials, fragments, and non-HTTPS schemes. - Allow bearer-authenticated requests only to an explicit allowlist of trusted AI Hive hostnames.
- If custom endpoints are a required development feature, require an explicit opt-in flag and a separately supplied credential rather than automatically reusing the production API key.
- Display the normalized destination hostname and require interactive confirmation before sending credentials to any non-default endpoint.
- Protect redirects by disabling them for authenticated API requests or validating every redirect target before forwarding the
Authorizationheader. - Treat environment and configuration values as untrusted input, applying the same validation regardless of their source.
- Add automated tests confirming rejection of HTTP URLs, deceptive subdomains, user-information components, alternate ports where inappropriate, and redirects to untrusted hosts.
- Document the custom-endpoint trust implications and advise affected users to revoke and rotate credentials if they may have used an untrusted base URL.
- Parse the endpoint with
