T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:94- Finding
Bearer API Key Can Be Forwarded to an Arbitrary Server
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:94-99, 128-143, 579-580; equivalent implementation inscripts/videogen.py:94-99, 128-143, 579-580
Vulnerability Type: Unrestricted credential destination
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 class AiHiveClient: """Encapsulates AI Hive OpenAPI HTTP requests.""" 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 def add_common_args(parser): parser.add_argument("--api-key", help="AI Hive API Key (sk-api-*)") parser.add_argument("--base-url", help=f"API Base URL (default {DEFAULT_BASE_URL})") parser.add_argument("--verbose", action="store_true", help="Detailed logging")Technical Analysis
The API base URL can be supplied through the
--base-urlcommand-line argument, theAI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. The value is accepted without validating its scheme or hostname.The same client then attaches the AI-HIVE bearer credential to every reques ...[truncated 1457 chars]
- Remediation
View remediation
Remediation Suggestions
- Pin authenticated production requests to
https://ai-hive.iclip.cn/api. - If custom endpoints are operationally necessary, require an explicit high-friction opt-in and display the exact credential destination before proceeding.
- Permit only HTTPS URLs and reject URLs containing user information, fragments, unexpected ports, or non-approved hostnames.
- Maintain an allowlist of trusted API hosts and validate the normalized hostname rather than using suffix-based string checks.
- Never reuse the production AI-HIVE credential for custom or development endpoints. Require a separate credential explicitly supplied for that endpoint.
- Prevent configuration files or untrusted inherited environment variables from silently overriding the credential destination.
- Add automated tests confirming that credentials are never transmitted to HTTP, localhost, private-network, or unapproved public destinations.
- Apply the same correction to both
scripts/imagegen.pyandscripts/videogen.py.
- Pin authenticated production requests to
