T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:113- Finding
API Credential Disclosure Through an Unrestricted Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:63-73,scripts/imagegen.py:113-137,scripts/imagegen.py:579-580,scripts/imagegen.py:827-831
Vulnerability Type: Bearer credential exposure to a user-configurable network origin
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: """封装 AI Hive OpenAPI HTTP 调用。""" 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_BASE_URL})") parser.add_argument("--verbose", action="store_true", help="详细日志")python config = Config( api_key=getattr(args, "api_key", None), base_url=getattr(args, "base_url", None), verbose=getattr(args, "verbose", False), )Technical Analysis
The API base URL can be selected through the
--base-urlcommand-line option, theAI_HIVE_BASE_URLenvironment variable, or the local configur ...[truncated 2514 chars]- Remediation
View remediation
Remediation Suggestions
- Enforce HTTPS for every API base URL and reject plaintext HTTP destinations.
- Restrict authenticated requests to an explicit allowlist, preferably only
ai-hive.iclip.cn. - If custom API endpoints are a required feature, require an explicit high-friction opt-in and display the exact destination before transmitting credentials.
- Do not automatically reuse the production AI Hive key for custom origins. Require a separate credential scoped to the selected origin.
- Normalize and validate URLs using a URL parser rather than string operations. Reject embedded credentials, unexpected ports, malformed hosts, and non-HTTP schemes.
- Validate redirects or disable cross-origin redirects for authenticated requests so the bearer header cannot reach another origin.
- Validate upload and result URL schemes and, where feasible, restrict them to approved object-storage domains.
- Document that environment variables and configuration files are security-sensitive inputs.
- After suspected exploitation, revoke and rotate the affected API key and review service activity for unauthorized use.
