T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
API Credential Disclosure Through an Unrestricted Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:91-100, 128-143, 528-530; duplicated inscripts/videogen.py:91-100, 128-143, 528-530
Vulnerability Type: CWE-200 — Exposure of Sensitive Information to an Unauthorized Actor
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 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="Detailed logging")Technical Analysis
The client accepts an API base URL from a command-line argument, the
AI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. It does not validate the URL scheme or restrict the destination to an approved AI-HIVE host.The same client unconditionally attaches the AI-HIVE bearer credential to every request sent through this base URL. Consequently, a maliciously supplied base URL can redirect credential-bearing API t ...[truncated 1368 chars]
- Remediation
View remediation
Remediation Suggestions
- Require HTTPS and reject URLs containing credentials, unexpected ports, fragments, or ambiguous host representations.
- Restrict credential-bearing requests to an explicit allowlist of approved AI-HIVE hostnames.
- If custom endpoints are required for development, require a conspicuous opt-in and a separate credential that is never an AI-HIVE production key.
- Construct requests through a dedicated session whose authentication is scoped to the approved origin.
- Disable redirects for authenticated API requests, or validate the scheme and destination of every redirect before following it.
- Refuse to forward the
Authorizationheader across origins. - Protect the configuration file and validate its ownership in addition to setting mode
0600. - Prefer environment-based secret injection over
--api-key, because command-line arguments may be exposed through process listings and shell history. - Add tests confirming that HTTP URLs, unapproved hosts, cross-origin redirects, loopback addresses, and private-network destinations are rejected.
