T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
Bearer Credential Disclosure Through a Configurable API Endpoint
- Content
View full analysis
Vulnerability Details
File Locations:
scripts/imagegen.py:91-98scripts/imagegen.py:128-143scripts/imagegen.py:583-588scripts/videogen.py:91-98scripts/videogen.py:128-143scripts/videogen.py:583-588
Vulnerability Type: Unrestricted credential-bearing endpoint configuration
Risk Level: MediumEvidence
The endpoint can be supplied through a command-line option, environment variable, or configuration file:
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_URLThe API key is then attached to every request sent through the configured base URL:
python 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 )The command-line interface explicitly permits an arbitrary base URL:
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")The same implementation is present in both generation scripts.
Technical Analysis
The scripts do not validate the scheme or hostname of the configured API endpoint before attaching the bearer credential. Consequently, a va ...[truncated 2092 chars]
- Remediation
View remediation
Remediation Suggestions
- Restrict the default client to an explicit allowlist of trusted HTTPS hosts, such as
ai-hive.iclip.cn. - Reject non-HTTPS URLs before constructing the client.
- Parse the URL with
urllib.parse.urlsplitand validate the normalized hostname rather than using string-prefix checks. - Do not send the production AI-HIVE credential to custom endpoints. Require a separate credential when custom endpoint support is necessary.
- Require an explicit high-visibility confirmation before using a non-default endpoint, displaying the exact hostname that will receive the credential.
- Ignore
AI_HIVE_BASE_URLin privileged, automated, or billing-sensitive execution contexts unless custom endpoints are explicitly enabled. - Protect
~/.ai-hive/config.jsonagainst replacement and symlink attacks before reading it; verify ownership and regular-file status where supported. - Add tests confirming that HTTP URLs, deceptive subdomains, user-information URL components, and unapproved hosts are rejected.
- Document immediate API-key revocation and rotation procedures for suspected exposure.
- Restrict the default client to an explicit allowlist of trusted HTTPS hosts, such as
