T09 · Insecure Skill Coding Practices
- Location
scripts/videogen.py:91- Finding
Unrestricted API Base URL Can Expose the AI-HIVE Bearer Credential
- Content
View full analysis
Vulnerability Details
File Location:
scripts/videogen.py, lines 91–100 and 130–144
Vulnerability Type: Unrestricted credential forwarding to a configurable endpoint
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: """封装 AI Hive OpenAPI HTTP 调用。""" 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 used without validating its scheme or hostname.AiHiveClientunconditionally attaches the AI-HIVE API key as anAuthorization: Bearerheader to requests constructed from this configurable base URL. Consequently, any party capable of influencing the command-line arguments, process environment, or configuration file can redirect authenticated requests to an arbitrary server.The implementation also does not require HTTPS. A base URL using plain HTTP would transmit the credential without transport encryptio ...[truncated 1717 chars]
- Remediation
View remediation
Remediation Suggestions
-
Allowlist the production API origin by default. Reject URLs whose normalized hostname is not
ai-hive.iclip.cn. -
Require HTTPS. Parse the URL with
urllib.parse.urlparseand reject non-HTTPS schemes, embedded credentials, unexpected ports, fragments, and malformed hostnames. -
Do not automatically forward production credentials to custom origins. If custom endpoints are required for development, require a separate development credential and an explicit option such as
--allow-custom-base-url. -
Add a high-friction confirmation for custom endpoints. Display the normalized destination origin and warn that an authorization credential will be sent. Non-interactive use should require a dedicated acknowledgement flag.
-
Separate authentication policy from generic request handling. Attach the bearer header only after verifying that the request destination matches the approved API origin.
-
Protect configuration integrity. Continue enforcing restrictive file permissions and additionally validate the stored
base_urlbefore using it. -
Prevent redirects from forwarding credentials to another origin. Disable redirects for authenticated API requests or validate every redirect target before following it.
-
Add regression tests covering malicious HTTP URLs, deceptive subdomains, embedded user information, alternate ports, malformed URLs, and unapproved HTTPS hosts.
A hardened validation pattern could resemble:
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("The API base URL host is not approved") if parsed.username or parsed.password: raise SystemExit("Embedded URL credentials are not ...[truncated 138 chars]-
