T09 · Insecure Skill Coding Practices
- Location
scripts/videogen.py:88- Finding
Caller-Controlled API Base URL Can Expose the AI-HIVE Bearer Credential
- Content
View full analysis
Vulnerability Details
File Location:
scripts/videogen.py:88-98,scripts/videogen.py:121-124, andscripts/videogen.py:134-136
Vulnerability Type: Unrestricted authenticated 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 def __init__(self, config): self.config = config self.base = config.base_url self.headers = { "Authorization": f"Bearer {config.api_key}", "Content-Type": "application/json", }python resp = requests.request( method, url, headers=self.headers, timeout=DEFAULT_TIMEOUT, **kwargs )Technical Analysis
The API base URL can be supplied through the
--base-urlcommand-line option, theAI_HIVE_BASE_URLenvironment variable, or the local 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 API request made against the selected base URL. Consequently, any party capable of influencing one of these configuration sources can redirect authenticated requests to a server they control.The issue also permits an
http://endpoint, which could expose the bearer credential through plaintext network transmission. This behavior exceeds the minimum privileges necessary for the declared functionality because normal operation only requires authenticated access to the legitimate AI-HIVE API.Attack Path
- An attacker influences a generated command, process environment, or
~/.ai-hive/config.json. - The attacker sets t ...[truncated 1587 chars]
- An attacker influences a generated command, process environment, or
- Remediation
View remediation
Remediation Suggestions
-
Restrict authenticated API requests to the official origin:
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("Untrusted API host") if parsed.username or parsed.password: raise SystemExit("Credentials are not allowed in the API URL") return value.rstrip("/") -
Apply validation consistently to command-line, environment, and configuration-file values.
-
If custom endpoints are needed for development, require an explicit opt-in development mode and use a separate test credential. Do not send production credentials to custom origins.
-
Construct authorization headers only after confirming that the destination origin is trusted. Avoid storing the bearer header as a client-wide default that can be applied to arbitrary URLs.
-
Disable redirects for authenticated requests or validate every redirect destination before forwarding credentials:
python requests.request( method, url, headers=self.headers, timeout=DEFAULT_TIMEOUT, allow_redirects=False, **kwargs, ) -
Add automated tests confirming rejection of:
- Non-HTTPS URLs.
- Unapproved hostnames.
- URLs containing embedded credentials.
- Lookalike and subdomain-confusion hosts.
- Configuration-file and environment-based endpoint overrides outside the allowlist.
-
Rotate any API keys that may previously have been used with an untrusted base URL.
-
