T09 · Insecure Skill Coding Practices
- Location
scripts/videogen.py:91- Finding
Bearer Credentials Can Be Sent to an Arbitrary or Plaintext API Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/videogen.py:91-100,scripts/videogen.py:128-143, andscripts/videogen.py:586-587
Vulnerability Type: Unvalidated credential destination
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 class AiHiveClient: """封装 AI Hive OpenAPI HTTP 调用。""" 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_BASE_URL})")Technical Analysis
The API base URL can come from the
--base-urlcommand-line argument, theAI_HIVE_BASE_URLenvironment variable, or the persistent configuration file. None of these sources is validated to ensure that:- The URL uses HTTPS.
- The destination is the legitimate AI-HIVE host.
- The URL contains a valid HTTP or HTTPS scheme.
- Sending the configured credential to the selected host has been explicitly authorized.
The resulting URL is passed to
requests.request()with anAuthorization: Bearerheader containing the AI-HIVE API key. Consequently, an attacker wh ...[truncated 1475 chars]- Remediation
View remediation
Remediation Suggestions
-
Require the base URL to use HTTPS:
python from urllib.parse import urlparse parsed = urlparse(candidate_url) if parsed.scheme != "https": raise SystemExit("The API base URL must use HTTPS.") -
Allowlist the official API hostname by default:
python ALLOWED_API_HOSTS = {"ai-hive.iclip.cn"} if parsed.hostname not in ALLOWED_API_HOSTS: raise SystemExit("Untrusted API hostname.") -
If custom enterprise endpoints are required, place them behind an explicit option such as
--allow-custom-api-hostand require interactive confirmation before transmitting credentials. -
Do not automatically reuse the production API key for a custom destination. Require a separately supplied credential for nonstandard hosts.
-
Reject URLs containing embedded user information, unexpected ports, fragments, or nonempty query strings.
-
Treat configuration-file ownership and permissions as part of validation. Reject files not owned by the current user rather than only attempting to change their mode after reading them.
-
Add automated tests confirming that HTTP URLs, lookalike domains, malformed URLs, and unauthorized custom hosts are rejected.
-
