T09 · Insecure Skill Coding Practices
- Location
scripts/videogen.py:92- Finding
Arbitrary API Base URL Can Expose the AI-HIVE Bearer Token
- Content
View full analysis
Vulnerability Details
File Location:
scripts/videogen.py, lines 92–143
Vulnerability Type: User-controlled authenticated request destination
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 class AiHiveClient: """Encapsulates AI Hive OpenAPI HTTP requests.""" 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 base URL is also exposed as a command-line option:
python parser.add_argument("--base-url", help=f"API Base URL (default {DEFAULT_BASE_URL})")Technical Analysis
The application resolves the API endpoint from three user-influenced sources: the
--base-urlcommand-line argument, theAI_HIVE_BASE_URLenvironment variable, and the local configuration file. The resolved value is accepted without validating its scheme, hostname, port, or origin.AiHiveClientthen attaches the AI-HIVE API key as a bearer token to every request made to that endpoint. Consequently, an attacker-controlled base URL receives the validAuthorizationheader on the initial HTTP request. The vulnerability a ...[truncated 1998 chars]- Remediation
View remediation
Remediation Suggestions
-
Remove endpoint overrides from production use. Always use the hard-coded trusted endpoint unless a dedicated development mode is explicitly enabled.
-
Apply an exact endpoint allowlist. Parse the configured URL with
urllib.parse.urlsplitand require:- Scheme exactly equal to
https. - Hostname exactly equal to
ai-hive.iclip.cn. - No embedded username or password.
- No unexpected port.
- No fragments or ambiguous path components.
- Scheme exactly equal to
-
Separate credentials by origin. Never attach an AI-HIVE bearer token to requests whose normalized origin does not match the approved API origin.
-
Control redirects. Disable automatic redirects for authenticated requests with
allow_redirects=False, or manually validate every redirect destination before following it. Never forward authorization headers to a different origin. -
Restrict configuration-file handling. Continue enforcing mode
0600, but reject unapprovedbase_urlvalues read from the file. Prefer storing only the API key and keeping the production endpoint immutable. -
Avoid command-line API keys. Remove or discourage
--api-key, because command-line arguments may be exposed through process listings and shell history. Prefer a protected configuration file, environment-based secret injection, or an operating-system credential store. -
Add security tests. Include tests confirming that HTTP endpoints, IP literals, lookalike domains, embedded credentials, unapproved ports, and cross-origin redirects are rejected before any authorization header is transmitted.
-
Incident response guidance. Advise users who may have used an untrusted base URL to revoke and rotate the affected API key and review account task and billing history.
-
