T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:92- Finding
API Key Disclosure Through an Unrestricted Base URL in the Image Generation Client
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py, lines 92-101 and 130-144
Vulnerability Type: Arbitrary authenticated endpoint and cleartext credential transmission
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 )Technical Analysis
The API base URL may be supplied through a command-line argument, the
AI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. The value is accepted without validating its scheme, hostname, port, or origin.The client subsequently includes the AI-HIVE bearer credential in every request made to the resulting URL. Consequently, a custom endpoint receives the same credential intended for the legitimate AI-HIVE service. The implementation also accepts plain HTTP URLs, allowing credentials to be exposed through network interception.
This is especially dangerous in automated agent environments, where environment variables or generated command arguments may be influenced by an untrusted wrapper, workspace configuration, or instruction source.
Attack Path
- An a ...[truncated 989 chars]
- Remediation
View remediation
Remediation Suggestions
- Require
httpsfor every authenticated API endpoint. - Allowlist the expected hostname, such as
ai-hive.iclip.cn, by default. - Reject URLs containing embedded credentials, fragments, unexpected ports, IP literals, or unsupported schemes.
- Prevent redirects to a different origin when an authorization header is present.
- If custom endpoints are a legitimate feature, require explicit informed consent and use a separate credential configured specifically for that endpoint.
- Do not automatically reuse an AI-HIVE production credential when the destination origin changes.
- Treat environment-provided endpoint overrides as untrusted input.
- Add tests verifying that HTTP URLs and unapproved hosts are rejected before any authenticated request is made.
- Require
