T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
API Credential Disclosure Through an Unrestricted Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py, lines 91–99 and 130–145
Vulnerability Type: User-controlled API destination with automatic bearer-token forwarding
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 destination can be supplied through
--base-url, theAI_HIVE_BASE_URLenvironment variable, or the local configuration file. The value is accepted without validating its scheme, hostname, port, or relationship to the legitimate AI-HIVE service.AiHiveClientsubsequently attaches the AI-HIVE API key as anAuthorization: Bearerheader to every request sent to that destination. Consequently, configuring an attacker-controlled URL causes the production credential to be transmitted directly to the attacker. Plain HTTP destinations are also accepted, allowing interception by a network-positioned attacker.Attack Path
- An attacker persuades the user or an automation environment to set
AI_HIVE_BASE_URL, pass--base-url, or modify~/.ai-hive/config.json. - The val ...[truncated 1005 chars]
- An attacker persuades the user or an automation environment to set
- Remediation
View remediation
Remediation Suggestions
- Require HTTPS for all authenticated API destinations.
- Allowlist the expected API hostname,
ai-hive.iclip.cn, by default. - Reject URLs containing embedded credentials, fragments, unexpected ports, or non-HTTP schemes.
- If custom endpoints are necessary for development, require an explicit opt-in and prominent confirmation before sending credentials.
- Use separate development credentials for custom endpoints rather than forwarding production AI-HIVE credentials.
- Revalidate the destination after redirects, or disable redirects for authenticated requests.
- Consider certificate pinning or equivalent transport controls in environments with elevated credential-protection requirements.
- Add automated tests verifying that HTTP URLs and unapproved hosts are rejected.
