T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
API Credentials Can Be Redirected to an Arbitrary Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:91-100, 126-144; duplicated inscripts/videogen.py:91-100, 126-144
Vulnerability Type: Unrestricted API endpoint override leading to credential disclosure
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 class AiHiveClient: """Encapsulates AI Hive OpenAPI HTTP calls.""" 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
Both generation clients allow the API base URL to be supplied through a command-line argument, the
AI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. The value is accepted without requiring HTTPS or validating that the destination belongs to the declared AI-HIVE service.The clients then attach the AI-HIVE bearer credential to every API request made through
_request. Consequently, changing the base URL redirects authenticated requests, including theAuthorizationheader, to an arbitrary server. Anhttp://endpoint is also accepted, allowing credentials and request ...[truncated 1367 chars]- Remediation
View remediation
Remediation Suggestions
- Remove custom base-URL support from these specialized Skill clients if it is not operationally required.
- Allowlist the exact expected origin, such as
https://ai-hive.iclip.cn, and reject all other hosts. - Require the
httpsscheme and reject URLs containing user information, unexpected ports, fragments, or ambiguous hostnames. - Apply authorization headers only after confirming that the final request origin matches the approved API origin.
- Disable automatic cross-origin redirects for authenticated requests, or validate every redirect target before following it.
- If custom endpoints are a required advanced feature, require explicit user confirmation and separate endpoint-specific credentials rather than reusing the AI-HIVE key.
- Apply the same correction to both
scripts/imagegen.pyandscripts/videogen.py.
