T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:97- Finding
Caller-Controlled API Base URL Can Exfiltrate the Bearer API Key
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py, lines 97-145; related argument exposure at lines 525-527 and client construction at lines 784-788
Vulnerability Type: Unvalidated credential destination / bearer-token disclosure
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: 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="Verbose logging")python config = Config( api_key=getattr(args, "api_key", None), base_url=getattr(args, "base_url", None), verbose=getattr(args, "verbose", False), ) client = AiHiveClient(config)Technical Analysis
The API destination is accepted from three caller-controlled sources:
- The
--base-urlcommand-li ...[truncated 2590 chars]
- The
- Remediation
View remediation
Remediation Suggestions
-
Restrict the default deployment to the official endpoint
Require the normalized origin to match:
text https://ai-hive.iclip.cnReject other schemes, hosts, embedded credentials, fragments, and unexpected ports.
-
Use an explicit allowlist when alternate deployments are required
Enterprise endpoints should be listed in trusted configuration controlled by an administrator. Do not treat an arbitrary CLI argument, environment variable, or user-editable configuration value as a trusted credential destination.
-
Require HTTPS
Reject plaintext HTTP endpoints. Validate the parsed URL with a URL parser rather than string-prefix checks.
-
Bind credentials to trusted origins
Add the bearer header only after confirming that the request destination matches an approved origin. Redirects should either be disabled for authenticated calls or checked so the authorization header is never forwarded to a different origin.
-
Require explicit confirmation for exceptional endpoints
If development servers must be supported, require an opt-in flag such as
--allow-custom-endpoint, display the exact origin receiving the credential, and avoid using production API keys with that mode. -
Harden configuration handling
Preserve the existing
0600permission enforcement, but validatebase_urlimmediately after loading it. Consider removingbase_urlfrom ordinary user configuration when only the official service is supported. -
Add security tests
Test rejection of HTTP URLs, deceptive subdomains, embedded credentials, alternate ports, malformed URLs, and attacker-controlled hosts. Also verify that cross-origin redirects never receive the authorization header.
-
