T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:74- Finding
API Credentials and User Media Can Be Redirected to an Attacker-Controlled Server
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:74-81,scripts/imagegen.py:116-129,scripts/imagegen.py:276-285, andscripts/imagegen.py:555-557
Vulnerability Type: Unrestricted API endpoint override and insufficient destination validation
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 _request(self, method, url, **kwargs): self.config.log(f"{method} {url}") try: resp = requests.request( method, url, headers=self.headers, timeout=DEFAULT_TIMEOUT, **kwargs ) except requests.exceptions.ConnectionError as e: raise SystemExit( f"Unable to connect to API server: {url}\n" f"Reason: {e}" )The authorization header used by this request is constructed as follows:
python self.headers = { "Authorization": f"Bearer {config.api_key}", "Content-Type": "application/json", }The upload destination is accepted from the API response:
python media_id = token["mediaId"] upload_url = token["upload"]["url"] upload_method = token["upload"].get("method", "PUT") upload_headers = token["upload"].get("headers", {}) with open(str(path), "rb") as f: try: oss_resp = requests.request( upload_method, upload_url, headers=upload_headers, data=f, timeout=300, )The alternate API endpoint is exposed through a command-line option:
python parser.add_argument("--api-key", help="AI Hive API Key (sk-api-*)") parser.add_argum ...[truncated 2652 chars]- Remediation
View remediation
Remediation Suggestions
- Allow only the expected production origin, such as
https://ai-hive.iclip.cn/api, during normal Skill execution. - If custom endpoints are required for development, place them behind an explicit option such as
--allow-unsafe-custom-endpointand display a clear warning before transmitting credentials. - Parse endpoints with
urllib.parse.urlparseand require:- The
httpsscheme. - A nonempty hostname.
- No embedded username or password.
- An allowlisted hostname and port.
- The
- Do not honor endpoint-related environment variables in production Skill mode unless this behavior is explicitly required and documented.
- Validate media upload and result download URLs independently. Require HTTPS and restrict destinations to approved object-storage domains.
- Consider using separate request sessions for authenticated API calls and unauthenticated storage transfers to prevent accidental authorization-header propagation.
- If an untrusted endpoint has previously been configured, revoke and rotate the affected API key and review usage records for unauthorized activity.
- Allow only the expected production origin, such as
