T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:93- Finding
Arbitrary API Base URL Can Expose Credentials and Uploaded Media in the Image Client
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:93-101,scripts/imagegen.py:133-143, andscripts/imagegen.py:270-290
Vulnerability Type: Unrestricted sensitive-data destination
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 token = client.create_upload_token(filename, content_type, size) media_id = token["mediaId"] upload_url = token["upload"]["url"] upload_method = token["upload"].get("method", "PUT") upload_headers = token["upload"].get("headers", {}) # PUT to object storage without the API key, using returned headers print(f"[2/3] Uploading file to object storage...") with open(str(path), "rb") as f: try: oss_resp = requests.request( upload_method, upload_url, headers=upload_headers, data=f, timeout=300, )Technical Analysis
The client accepts its API base URL from a command-line option, the
AI_HIVE_BASE_URLenvironment variable, or the local configuration file without validating the URL scheme or destination host. The ...[truncated 2209 chars]- Remediation
View remediation
Remediation Suggestions
- Default to and allow only
https://ai-hive.iclip.cn/apifor normal operation. - Parse URLs with
urllib.parse.urlparseand reject:- Schemes other than HTTPS.
- URLs containing embedded usernames or passwords.
- Missing or malformed hostnames.
- Unexpected ports.
- Hosts outside an explicit allowlist.
- If custom endpoints are a required development feature, place them behind an explicit opt-in such as
--allow-custom-endpoint, display the destination hostname, and require interactive confirmation before sending credentials. - Do not reuse an AI-HIVE credential with unrelated custom endpoints. Require a separate credential explicitly scoped to the custom service.
- Validate server-provided upload URLs before transferring files. Require HTTPS and restrict them to documented object-storage domains.
- Restrict upload methods to the documented method, preferably
PUT, rather than executing an arbitrary method returned by the server. - Add automated tests confirming that HTTP URLs, deceptive subdomains, embedded credentials, and unapproved upload hosts are rejected.
- Advise affected users to revoke and rotate any API key used after connecting to an untrusted custom endpoint.
- Default to and allow only
