T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
API Bearer Credential Can Be Redirected to an Arbitrary Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:91-100, 130-143, 587;scripts/videogen.py:91-100, 130-143, 587
Vulnerability Type: Unrestricted credential-bearing endpoint configuration
Risk Level: HighVulnerable Code
The same implementation is present in both
scripts/imagegen.pyandscripts/videogen.py: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 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")Technical Analysis
The scripts accept an API base URL from three externally controllable sources:
- The
--base-urlcommand-line argument. - The
AI_HIVE_BASE_URLenvironment variable. - The persistent
base_urlproperty in~/.ai-hive/config.json.
No origin allowlist, HTTPS requirement, hostname validation, or credential-forwarding warning is applied. After resolving the URL, the clie ...[truncated 2228 chars]
- The
- Remediation
View remediation
Remediation Suggestions
-
Restrict authenticated requests to an explicit allowlist containing the official AI-HIVE origin:
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("Refusing to send credentials to an untrusted API host.") if parsed.username or parsed.password: raise SystemExit("User information is not allowed in the API URL.") return value.rstrip("/") -
Apply validation consistently to CLI, environment, and configuration-file values.
-
If custom endpoints are required for development, require a separate explicit flag such as
--allow-custom-endpoint, display the destination origin, and request interactive confirmation before attaching credentials. -
Do not reuse an AI-HIVE production credential with a custom endpoint. Require a separately supplied development credential for nonstandard origins.
-
Reject plaintext HTTP endpoints and unexpected URL components, including embedded credentials, fragments, and suspicious redirects.
-
Disable automatic redirects for credential-bearing requests or validate every redirect target before forwarding the
Authorizationheader. -
Add automated tests confirming that credentials are never sent when the target host is outside the allowlist.
-
