T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:92- Finding
API Credential Disclosure Through an Unrestricted Custom API Origin
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:92-99,scripts/imagegen.py:133-143, andscripts/imagegen.py:587
Vulnerability Type: Credential disclosure through user-controlled API endpoint
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 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
The API base URL can be supplied through the
--base-urlcommand-line argument, theAI_HIVE_BASE_URLenvironment variable, or the local configuration file. No scheme validation, hostname allowlist, or credential-origin binding is performed.Independently, the client creates a global request header containing the resolved API key:
http Authorization: Bearer <API_KEY>This header is attached to every API request regardless of the selected destination. Consequently, changing the API base URL to an attacker-controlled server causes the application to transmit the user's saved AI Hive API key to that server.
HTTPS is not required, ...[truncated 1938 chars]
- Remediation
View remediation
Remediation Suggestions
-
Restrict credential-bearing requests to an explicit allowlist of trusted HTTPS origins:
python from urllib.parse import urlparse TRUSTED_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 TRUSTED_API_HOSTS: raise SystemExit("The API base URL is not trusted") if parsed.username or parsed.password: raise SystemExit("Credentials in the API URL are not permitted") return value.rstrip("/") -
Bind stored credentials to their intended origin. Do not load the default AI Hive key when a non-default endpoint is selected.
-
If custom API servers are a required feature, require the user to provide a separate credential explicitly for that server. Display a clear confirmation identifying the destination before sending it.
-
Reject plaintext HTTP endpoints whenever an authorization header or other sensitive data will be transmitted.
-
Disable redirects for credential-bearing requests, or validate every redirect destination before following it. This prevents a trusted endpoint from redirecting an authenticated request to an untrusted origin.
-
Add automated tests confirming that the authorization header is never sent to an unapproved hostname.
-
