T09 · Insecure Skill Coding Practices
- Location
scripts/videogen.py:94- Finding
API Credential Disclosure Through an Unrestricted Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/videogen.py:94-99, 126-143
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", } 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-urlcommand-line option, theAI_HIVE_BASE_URLenvironment variable, or the local configuration file. The value is accepted without validating its scheme, hostname, port, or trust relationship with AI-HIVE.Every request made through
_requestattaches the AI-HIVE bearer credential in theAuthorizationheader. Consequently, if an attacker can influence any base URL configuration source, authenticated requests are redirected to the attacker’s server and disclose the API key. The implementation also does not require HTTPS, so credentials may be transmitted over plaintext HTTP.Attack Path
- An attacker influences the execution environment, command invocation, or
~/.ai-hive/config.json. - The attacker sets
AI_HIVE_BASE_URLor--base-urlto an atta ...[truncated 883 chars]
- An attacker influences the execution environment, command invocation, or
- Remediation
View remediation
Remediation Suggestions
- Restrict authenticated API requests to an explicit allowlist of approved AI-HIVE HTTPS hostnames.
- Parse URLs with
urllib.parse.urlparseand reject:- Schemes other than
https - Embedded usernames or passwords
- Unexpected hostnames or ports
- Loopback, private, link-local, and other non-approved network destinations
- Schemes other than
- Do not attach an AI-HIVE credential to arbitrary custom endpoints. If custom endpoints are a required feature, use a separate credential explicitly supplied for that endpoint.
- Disable cross-origin redirects or validate every redirect destination before forwarding the
Authorizationheader. - Require explicit interactive confirmation when changing the configured service endpoint.
- Store the expected endpoint origin alongside the credential and refuse to use that credential for a different origin.
- Add automated tests proving that HTTP endpoints, unapproved hosts, and cross-origin redirects are rejected.
