T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
Unrestricted API endpoint can disclose the bearer token
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:91-100,scripts/imagegen.py:130-143,scripts/imagegen.py:776-777,scripts/imagegen.py:813
Vulnerability Type: User-controlled API endpoint with credential forwarding
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 a command-line argument, the
AI_HIVE_BASE_URLenvironment variable, or the local configuration file. The implementation does not enforce HTTPS or restrict the destination to an approved hostname.The same AI Hive API key is subsequently placed in the
Authorizationheader for every request sent to the selected endpoint. Consequently, an attacker who controls the endpoint configuration can cause the client to transmit the bearer credential to an attacker-operated server. Supplying an unencrypted HTTP endpoint would also expose the credential to network interception.Attack Path
...[truncated 992 chars]
- Remediation
View remediation
Remediation Suggestions
- Restrict normal operation to an explicit allowlist such as
https://ai-hive.iclip.cn/api. - Parse the URL with
urllib.parse.urlparseand require thehttpsscheme, the expected hostname, and an approved path prefix. - Reject URLs containing user information, unexpected ports, fragments, or ambiguous hostname representations.
- Do not send the production bearer token to a custom host. If custom endpoints are required for development, require a separate credential and an explicit high-friction opt-in.
- Warn or fail securely when the environment or configuration file attempts to override the production endpoint.
- Add automated tests covering HTTP URLs, lookalike domains, embedded credentials, redirects, and localhost/private-network destinations.
- Restrict normal operation to an explicit allowlist such as
