T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:118- Finding
Bearer Credential Disclosure Through an Unrestricted API Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:118-144, 587andscripts/videogen.py:118-144, 587
Vulnerability Type: Server-side credential disclosure caused by an unrestricted endpoint override
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 )python parser.add_argument("--base-url", help=f"API Base URL (default {DEFAULT_BASE_URL})")Technical Analysis
Both generation scripts permit the API origin to be supplied through the
--base-urlargument, theAI_HIVE_BASE_URLenvironment variable, or the local configuration file. The selected value is not restricted to the official AI-HIVE host, is not required to use HTTPS, and is not checked for embedded credentials or an unexpected port.Every request made through
AiHiveClient._request()automatically receives the AI-HIVE API key in anAuthorization: Bearerheader. Consequently, changing the base URL redirects authenticated requests—and the bearer credential itself—to an attacker-controlled endpoint.The vulnerable behavior affects all authenticate ...[truncated 1302 chars]
- Remediation
View remediation
Remediation Suggestions
- Allow only the official HTTPS API origin during normal operation:
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("Unapproved API host") if parsed.username or parsed.password: raise SystemExit("Embedded URL credentials are prohibited") return value.rstrip("/") - Remove
--base-urlfrom production-facing commands unless custom endpoints are genuinely required. - If development endpoints are necessary, require an explicit unsafe-development option and a separate non-production credential.
- Do not attach an authorization header until the final request URL has passed scheme, hostname, and port validation.
- Ignore or reject untrusted
base_urlvalues loaded from the configuration file. - Apply the same correction to both
scripts/imagegen.pyandscripts/videogen.py. - Rotate any API key that may already have been used with an untrusted base URL.
- Allow only the official HTTPS API origin during normal operation:
