T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
API Credential Disclosure Through an Unrestricted API Endpoint Override
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:91-100, 130-143, 586-587
Vulnerability Type: Unvalidated service endpoint with bearer-token forwarding
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 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})")Technical Analysis
The API base URL can be supplied through a command-line option, the
AI_HIVE_BASE_URLenvironment variable, or the local configuration file. The code removes only trailing slashes and performs no validation of the URL scheme, hostname, port, or trust relationship.The HTTP client then includes the AI-HIVE bearer credential in every request sent to the resulting endpoint. Consequently, control over any base-URL input is equivalent to control over the destination that receives the API key. This violates the security principle that credentials must only be forwarded to authenticated and explicitly trusted origins.
The issue can also affect uploaded media. After receiving an authenticated upload-token request, ...[truncated 1920 chars]
- Remediation
View remediation
Remediation Suggestions
- Keep the production API origin immutable unless endpoint overriding is explicitly required for development.
- Parse override values with a standard URL parser and require HTTPS.
- Enforce an allowlist of approved API hostnames and ports before creating the client.
- Reject URLs containing credentials, fragments, unexpected paths, nonstandard ports, or ambiguous host representations.
- Bind authorization headers to the approved API origin. Never forward bearer credentials merely because a URL was supplied through CLI, environment, or configuration.
- Treat endpoint overrides as an unsafe development feature requiring an explicit option such as
--allow-unsafe-endpoint, and display a prominent warning that credentials may be disclosed. - Validate upload-token responses before transmitting files. Require HTTPS and approved object-storage domains, and restrict upload methods to the documented set.
- Validate result-download URLs similarly to reduce exposure to malicious or unintended network destinations.
- Consider removing
base_urlfrom the API-key configuration file so that modification of a credential store cannot silently redirect authentication traffic. - Add automated tests confirming that unapproved schemes, hosts, ports, upload URLs, and download URLs are rejected before any credential or media is transmitted.
