T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:91- Finding
API Credential Disclosure Through an Unrestricted Custom Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:91-99, 130-133, 587
Vulnerability Type: Bearer-token disclosure through an attacker-controlled API origin
Risk Level: MediumVulnerable 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", }python parser.add_argument("--base-url", help=f"API Base URL (default {DEFAULT_BASE_URL})")Technical Analysis
The API base URL can be supplied through the
--base-urlargument, theAI_HIVE_BASE_URLenvironment variable, or the local configuration file. The value is used without validating its scheme or hostname.The HTTP client independently constructs an
Authorization: Bearerheader containing the user's AI-HIVE API key and attaches that header to every API request. Consequently, changing the base URL also changes the recipient of the credential.This violates the expected trust boundary for an API credential: a token intended for
ai-hive.iclip.cncan be transmitted to any HTTP or HTTPS server. Plain HTTP endpoints are also accepted, allowing interception by a network attacker.Attack Path
- The victim has a valid AI-HIVE key in
AI_HIVE_API_KEY, a CLI argument, or~/.ai-hive/config.json. - An attacker causes the victim to use a malicious endpoint through one of the supported configuration mechanisms, for example:
bash python3 scripts/imagegen.py generate
...[truncated 1124 chars]
- The victim has a valid AI-HIVE key in
- Remediation
View remediation
Remediation Suggestions
- Restrict the normal client to the expected 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("The API hostname is not trusted") if parsed.username or parsed.password: raise SystemExit("Credentials in the API URL are not allowed") return value.rstrip("/") - Do not send an AI-HIVE credential to a custom origin automatically.
- If self-hosted or development endpoints are genuinely required, require an explicit unsafe-development option and a separate credential.
- Reject plaintext HTTP and URLs containing embedded user information.
- Display the normalized credential destination and require confirmation before first use of any non-default endpoint.
- Document that environment and configuration-file changes can alter the credential destination.
- Rotate any API key that may already have been transmitted to an untrusted endpoint.
- Restrict the normal client to the expected origin:
