T09 · Insecure Skill Coding Practices
- Location
scripts/minimax_api.py:31- Finding
Unrestricted API Host Override Can Expose Credentials and User Content
- Content
View full analysis
Vulnerability Details
File Location:
scripts/minimax_api.py, lines 31-37, with credential transmission at lines 44-59 and 109-141
Vulnerability Type: Unvalidated network destination for authenticated requests
Risk Level: HighVulnerable Code
python def _get_config(): """Return (api_key, api_host, api_base). Raises if key is missing.""" api_key = os.environ.get("MINIMAX_API_KEY", "") if not api_key: raise RuntimeError("MINIMAX_API_KEY environment variable is not set") api_host = os.environ.get("MINIMAX_API_HOST", DEFAULT_API_HOST).rstrip("/") return api_key, api_host, api_host + "/v1"The resulting destination is used for authenticated API requests:
python def _api_request(endpoint, method="GET", body=None, timeout=120, query=None): """Make an API request and return the parsed JSON response.""" api_key, _, api_base = _get_config() url = api_base + "/" + endpoint if query: sep = "&" if "?" in url else "?" url += sep + urllib.parse.urlencode(query) data = None if body is not None: data = json.dumps(body, ensure_ascii=False).encode("utf-8") req = urllib.request.Request(url, data=data, method=method) req.add_header("Authorization", "Bearer " + api_key) if body is not None: req.add_header("Content-Type", "application/json; charset=utf-8")It also controls the destination for local file uploads:
python def _upload_file(filepath, purpose="image"): """Upload a file and return file_id.""" api_key, _, api_base = _get_config() url = api_base + "/files/upload" import mimetypes mime = mimetypes.guess_type(filepath)[0] or "application/octet-stream" boundary = uuid.uuid4().hex with open(filepath, "rb") as f: file_data = f.read() filename = os.path.basename(filepath) body_parts = [] body_parts.append(("--" + boundary).encode()) body_parts.append( ('Content-Disposition: form-da ...[truncated 3604 chars]- Remediation
View remediation
Remediation Suggestions
- Remove
MINIMAX_API_HOSTconfigurability unless custom endpoints are an essential supported requirement. - If an override is necessary, parse it with
urllib.parse.urlsplit()and enforce:- HTTPS only.
- An explicit allowlist of trusted hostnames, preferably only
api.minimaxi.com. - No embedded username or password.
- No fragment or query string.
- No unexpected path.
- No nonstandard port unless explicitly approved.
- Resolve and compare the final request origin before adding the
Authorizationheader. - Disable redirects or ensure authorization headers are never forwarded across origins.
- Require explicit user confirmation before uploading local files, clearly identifying both the file and destination.
- Reject plain HTTP even for custom hosts.
- Consider separating credentials by allowed origin so a MiniMax credential cannot be attached to arbitrary requests.
- Add automated tests confirming that attacker-controlled hosts, malformed URLs, HTTP URLs, embedded credentials, and cross-origin redirects are rejected.
A hardened configuration pattern could use a fixed endpoint:
python DEFAULT_API_HOST = "https://api.minimaxi.com" def _get_config(): api_key = os.environ.get("MINIMAX_API_KEY", "") if not api_key: raise RuntimeError("MINIMAX_API_KEY environment variable is not set") return api_key, DEFAULT_API_HOST, DEFAULT_API_HOST + "/v1"If override support must remain, validate the parsed origin against a strict allowlist before constructing any request or attaching credentials.
- Remove
