T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
Bearer Credential Disclosure Through an Unrestricted API Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:91-99, 130-143, 583-587, 747-752, 821-834
Vulnerability Type: Server endpoint injection leading to bearer credential 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: """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 )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=api_key, base_url=base_url, verbose=verbose) client = AiHiveClient(config)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 client accepts an arbitrary API base URL from the
--base-urlcommand-line option, theAI_HIVE_BASE_URLenvironment variab ...[truncated 2172 chars]- Remediation
View remediation
Remediation Suggestions
-
Allowlist credential-bearing destinations. Permit the production API key to be sent only to the expected HTTPS origin, such as:
python from urllib.parse import urlparse ALLOWED_API_HOSTS = {"ai-hive.iclip.cn"} def validate_base_url(value): parsed = urlparse(value) if parsed.scheme != "https": raise SystemExit("The API base URL must use HTTPS") if parsed.hostname not in ALLOWED_API_HOSTS: raise SystemExit("The API host is not authorized") if parsed.username or parsed.password: raise SystemExit("Credentials in the API URL are prohibited") return value.rstrip("/") -
Validate every source. Apply the same validation to CLI, environment, and persisted configuration values rather than validating only the default endpoint.
-
Separate custom-endpoint credentials. If custom API endpoints are required for development, require a distinct credential explicitly supplied for that endpoint. Never automatically forward the production AI-HIVE key.
-
Reject plaintext transport. Prohibit
http://URLs and retain TLS certificate verification. -
Reduce configuration exposure. Avoid persisting arbitrary API base URLs alongside production credentials. Consider ignoring persisted custom endpoints unless an explicit development mode is enabled.
-
Add regression tests. Verify that HTTP URLs, unapproved hosts, URLs containing user information, hostname-confusion forms, and attacker-controlled environment values are rejected before any network request occurs.
-
Respond to suspected exposure. Revoke and rotate any key that may have been sent to an untrusted endpoint, then inspect API usage and billing records for unauthorized activity.
-
