T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:274- Finding
Unrestricted Server-Controlled Upload and Download URLs in Image Client
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py, lines 274-320
Vulnerability Type: Server-controlled request destination and HTTP method
Risk Level: MediumTechnical Analysis
The image client accepts an upload URL, HTTP method, and headers directly from the API response and passes them to
requests.requestwithout validating the URL scheme, destination host, resolved IP address, or allowed method. The same client later performs a GET request against an unrestricted result URL supplied by the server.python token = client.create_upload_token(filename, content_type, size) media_id = token["mediaId"] upload_url = token["upload"]["url"] upload_method = token["upload"].get("method", "PUT") upload_headers = token["upload"].get("headers", {}) # PUT to object storage without the API key, using returned headers print(f"[2/3] Uploading file to object storage...") with open(str(path), "rb") as f: try: oss_resp = requests.request( upload_method, upload_url, headers=upload_headers, data=f, timeout=300, ) except requests.exceptions.RequestException as e: raise SystemExit( f"OSS upload network error: {e}\n" "Check the network connection or whether the file is too large" )python def download_file(url, out_path, timeout=300): """Stream a file download with progress display.""" print(f"[download] {out_path.name}") try: resp = requests.get(url, stream=True, timeout=timeout) resp.raise_for_status() total = int(resp.headers.get("content-length", 0)) downloaded = 0 with open(str(out_path), "wb") as f:A malicious or compromised configured API endpoint could return a URL resolving to a loopback, link-local, or private-network service. More significantly, the upload flow also permits the server to select methods other than ...[truncated 2418 chars]
- Remediation
View remediation
Remediation Suggestions
- Require
httpsfor API, upload, redirect, and result URLs. - Restrict upload methods to the documented method, preferably exactly
PUT. - Reject server-supplied hop-by-hop, authentication, proxy, host, and forwarding headers; allow only explicitly required object-storage headers.
- Validate destination hosts against an approved object-storage and result-CDN allowlist.
- Resolve destination names and reject loopback, private, link-local, multicast, reserved, and cloud metadata IP ranges for both IPv4 and IPv6.
- Disable automatic redirects or revalidate every redirect destination before following it.
- Apply a configurable maximum upload size before opening the file.
- Apply a maximum download size while streaming, independent of the potentially untrusted
Content-Lengthheader. - Write downloads to a temporary file and atomically rename them only after size and media-type validation succeeds.
- Clearly display the resolved upload destination and require confirmation when it is outside the provider's approved domains.
- Require
