T09 · Insecure Skill Coding Practices
- Location
scripts/videogen.py:91- Finding
API Credential Disclosure Through an Unrestricted Custom Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/videogen.py:91-99, 130-143
Vulnerability Type: Unrestricted authenticated endpoint configuration
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 )Technical Analysis
The API base URL can be supplied through the
--base-urlargument, theAI_HIVE_BASE_URLenvironment variable, or the local configuration file. The application does not validate the URL scheme or restrict the destination hostname.The HTTP client subsequently attaches the AI Hive bearer credential to every API request sent to the configured destination. Consequently, an attacker who can influence command-line arguments, environment variables, or
~/.ai-hive/config.jsoncan redirect an authenticated request to an attacker-controlled server.The absence of an HTTPS requirement also permits configuration of a plaintext HTTP endpoint, exposing the bearer token to network interception.
Attack Path
- The victim has a valid AI Hive API key configured through the environment, command line, or
~/.ai-hive/config.json. - An attacker causes the base URL to resolve to an attacker-control ...[truncated 1092 chars]
- The victim has a valid AI Hive API key configured through the environment, command line, or
- Remediation
View remediation
Remediation Suggestions
- Default to an allowlist containing only the official API origin, such as
https://ai-hive.iclip.cn/api. - Parse custom URLs with a standard URL parser and reject malformed URLs, embedded credentials, fragments, and unsupported schemes.
- Require HTTPS for all authenticated requests. Permit plaintext HTTP only for an explicitly enabled local-development mode, and never send production credentials in that mode.
- If custom API hosts are a required feature, require an explicit opt-in and display the exact destination before transmitting credentials.
- Restrict custom destinations to approved hostnames or certificate identities rather than relying only on string-prefix checks.
- Avoid automatically attaching the AI Hive bearer token to arbitrary URLs. Build authenticated requests only for validated API origins.
- Protect the configuration file and its parent directory from unauthorized modification, and document that environment and command-line overrides affect where credentials are sent.
- Rotate any API key that may already have been used with an untrusted base URL, and review the associated account for unexpected usage.
- Default to an allowlist containing only the official API origin, such as
