T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:94- Finding
Configurable API Endpoint Can Expose Bearer Credentials to an Untrusted Server
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:94-100,scripts/imagegen.py:132-144, andscripts/imagegen.py:587
Vulnerability Type: Unrestricted credential destination and missing transport enforcement
Risk Level: MediumVulnerable 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 self.headers = { "Authorization": f"Bearer {config.api_key}", "Content-Type": "application/json", }python 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
The authenticated API destination can be overridden through a command-line argument, the
AI_HIVE_BASE_URLenvironment variable, or~/.ai-hive/config.json. The resulting URL is used without validating its scheme or hostname.Every request made through
AiHiveClient._request()includes the AI Hive bearer credential. Consequently, a custom endpoint receives the sameAuthorizationheader intended for the official AI Hive service. The implementation also permits a plaintexthttp://endpoint, allowing credentials and request contents to be exposed to a network attacker.Exploitation requires influence over the command invocation, process environment, or configuration file. This could occur through malicious setup instructions, a poisoned shell environment, configuration tampering by another pr ...[truncated 1530 chars]
- Remediation
View remediation
Remediation Suggestions
- Require the API base URL to use HTTPS and reject plaintext HTTP:
python from urllib.parse import urlparse parsed = urlparse(base_url) if parsed.scheme != "https": raise SystemExit("The API base URL must use HTTPS") - Allowlist the official hostname,
ai-hive.iclip.cn, for requests that carry an AI Hive API key. - If custom endpoints are a legitimate feature, require a separate credential for each origin and never automatically forward an AI Hive credential to a non-official host.
- Display the resolved hostname and require explicit interactive confirmation before sending credentials to a custom endpoint.
- Reject URLs containing embedded user information, unexpected ports, fragments, or malformed hostnames.
- Document the security implications of
--base-urlandAI_HIVE_BASE_URL. - Provide API-key revocation and rotation guidance for users who may have connected to an untrusted endpoint.
- Require the API base URL to use HTTPS and reject plaintext HTTP:
