T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:64- Finding
API Credential Disclosure Through an Unrestricted Custom Base URL in Image Generation Client
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:64-100,scripts/imagegen.py:131-143, andscripts/imagegen.py:571-573
Vulnerability Type: Credential disclosure through an attacker-controlled API endpoint
Risk Level: MediumVulnerable Code
python def __init__(self, api_key=None, base_url=None, verbose=False): self.verbose = verbose self.api_key = self._resolve_api_key(api_key) self.base_url = self._resolve_base_url(base_url) def _resolve_api_key(self, cli_key): if cli_key: return cli_key env_key = os.environ.get("AI_HIVE_API_KEY") if env_key: return env_key file_config = self._read_config_file() if file_config.get("api_key"): return file_config["api_key"]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 _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("--api-key", help="AI Hive API Key (sk-api-*)") parser.add_argument("--base-url", help=f"API Base URL (default {DEFAULT_BASE_URL})")Technical Analysis
The client obtains an AI-HIVE API key from a command-line argument, environment variable, or local configuration file. Independently, i ...[truncated 1947 chars]
- Remediation
View remediation
Remediation Suggestions
- Restrict authenticated production requests to an explicit allowlist, preferably only
https://ai-hive.iclip.cn/api. - Parse the destination with a standard URL parser and reject unsupported schemes, embedded credentials, unexpected ports, malformed hosts, redirects to untrusted hosts, and non-HTTPS URLs.
- If custom endpoints are required for development, require a clearly named opt-in flag such as
--allow-untrusted-base-urland do not automatically attach production credentials to those endpoints. - Use a separate development credential for custom servers and require interactive confirmation that identifies the exact destination host.
- Remove or discourage
--api-key; prefer an environment variable or a configuration file protected with mode0600. - Ensure redirects cannot forward the
Authorizationheader to a different origin. - Add automated tests confirming that credentials are never sent to non-allowlisted hosts or over plaintext HTTP.
- Restrict authenticated production requests to an explicit allowlist, preferably only
