T09 · Insecure Skill Coding Practices
- Location
scripts/videogen.py:91- Finding
Configurable API Endpoint Can Exfiltrate the Bearer API Key
- Content
View full analysis
Vulnerability Details
File Location:
scripts/videogen.py, lines 91–100 and 130–143
Vulnerability Type: Unrestricted credential forwarding to a configurable endpoint
Risk Level: HighComplete Code Snippet
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 class AiHiveClient: """Encapsulates AI Hive OpenAPI HTTP calls.""" 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 )The custom endpoint is exposed through the CLI at line 587:
python parser.add_argument("--base-url", help=f"API Base URL (default {DEFAULT_BASE_URL})")Technical Analysis
The client permits its API base URL to be controlled through a command-line argument, the
AI_HIVE_BASE_URLenvironment variable, or the local configuration file. It does not require HTTPS and does not validate the destination against an approved hostname list.The client independently constructs an
Authorizationheader containing the resolved AI-HIVE API key and attaches it to every API request. Consequently, selecting an attacker-controlled base URL causes the legitimate bearer credential to be transmitted directly to that server.Supporting custom deployments can be l ...[truncated 1660 chars]
- Remediation
View remediation
Remediation Suggestions
- Allow only
https://endpoints and reject URLs containing user information, fragments, unexpected ports, or non-HTTP(S) schemes. - Permit the default production hostname through an explicit allowlist. If additional official hosts are required, enumerate them rather than accepting arbitrary destinations.
- Disable custom base URLs by default. Place development endpoints behind a conspicuous option such as
--allow-custom-endpoint. - Do not reuse a production API key when the destination host differs from the official service. Require a separately supplied credential after displaying the exact destination.
- Reject redirects to different origins, or remove the authorization header before any cross-origin redirect.
- Validate configuration-file ownership and reject files writable by other users, in addition to tightening read permissions.
- Display a warning and require confirmation before sending credentials to a non-default endpoint.
- Add automated tests verifying that HTTP URLs, unapproved hosts, cross-origin redirects, and malformed URLs cannot receive the bearer token.
- If exposure is suspected, revoke the affected key, issue a replacement, and review account usage and billing records.
- Allow only
