T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:122- Finding
Configurable API endpoint can disclose the bearer API key
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:122-143, 567-568; duplicated inscripts/videogen.py:122-143, 567-568
Vulnerability Type: Unrestricted authenticated endpoint configuration
Risk Level: HighVulnerable Code
python class AiHiveClient: """Encapsulates AI Hive OpenAPI HTTP calls.""" 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")The endpoint may also be obtained from an 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_URLTechnical Analysis
The client automatically adds the AI-HIVE bearer token to every request made through
_request. At the same time, the destination base URL can be supplied through--base-url,AI_HIVE_BASE_URL, or~/.ai-hive/config.json.No validation restricts ...[truncated 1668 chars]
- Remediation
View remediation
Remediation Suggestions
- Require the
httpsscheme for every authenticated API endpoint. - Allow authenticated requests only to an explicit hostname allowlist, such as the documented AI-HIVE API hostname.
- Reject URLs containing user information, fragments, unsupported ports, ambiguous host encodings, or non-network schemes.
- If custom endpoints are required for development, require a separate opt-in flag and a separate credential that is not valid against production.
- Display a prominent confirmation before transmitting credentials to a non-default endpoint.
- Validate redirect destinations and prevent the authorization header from being forwarded to a different origin.
- Apply the same correction to both
imagegen.pyandvideogen.py. - Add tests covering plain HTTP URLs, deceptive subdomains, URL user information, alternate ports, redirects, and attacker-controlled environment variables.
- Require the
