T09 · Insecure Skill Coding Practices
- Location
scripts/image.py:91- Finding
Unrestricted Image Download Enables Server-Side Request Forgery and Resource Exhaustion
- Content
View full analysis
Vulnerability Details
File Location:
scripts/image.py, lines 91-95
Vulnerability Type: Server-Side Request Forgery (SSRF), unbounded response handling, and unrestricted file output
Risk Level: MediumVulnerable Code
python def download_image(image_url: str, output_path: str) -> str: resp = requests.get(image_url, timeout=60) resp.raise_for_status() with open(output_path, "wb") as f: f.write(resp.content) return output_pathTechnical Analysis
The publicly documented
download_imagefunction performs a server-side request to an arbitrary caller-provided URL. It does not validate:- The URL scheme or destination hostname.
- Whether DNS resolution produces a loopback, private, link-local, multicast, or reserved IP address.
- Redirect destinations.
- The response content type or actual file format.
- The maximum response size.
- Whether
output_pathis confined to an approved output directory.
Consequently, a caller that controls
image_urlcan direct the Agent host to request internal or otherwise non-public HTTP services. Redirects followed automatically byrequestscan also lead the request to a prohibited destination. The 60-second timeout limits request duration but not response size. Accessingresp.contentbuffers the complete response in memory before writing it, allowing a large response to consume substantial memory and disk capacity.The same helper is also used for URLs returned by the MiniMax image-generation API. Those URLs cross a remote trust boundary and should not be treated as inherently safe without destination and response validation.
Attack Path
- An attacker or untrusted workflow supplies a URL to the documented
download_imagefunction, or causes a remote API response to contain a hostile download URL. - The URL points directly to an internal endpoint, cloud metadata service, loopback service, or an external endpoint that redirects to one.
requests.get()issues ...[truncated 1315 chars]
- Remediation
View remediation
Remediation Suggestions
- Permit only
httpsURLs and reject URLs containing embedded credentials or unsupported schemes. - Resolve the hostname before connecting and reject every loopback, private, link-local, multicast, unspecified, and reserved IPv4 or IPv6 address.
- Prevent DNS rebinding by connecting only to the validated address while preserving correct TLS hostname verification, or use a hardened outbound proxy.
- Disable redirects, or validate the scheme, hostname, and resolved addresses at every redirect hop.
- Prefer an explicit allowlist of trusted image-delivery domains. If only MiniMax-generated images should be downloaded, document and enforce the expected MiniMax/CDN hosts.
- Use
stream=Trueand enforce a strict maximum byte count before and during download rather than accessingresp.content. - Validate the response
Content-Type, then inspect file signatures and decode the image with a safe image library before accepting it. - Constrain output files to a dedicated directory. Resolve the final path and verify that it remains beneath that directory; reject traversal and unsafe symlink targets.
- Use exclusive file creation or an explicit overwrite policy to prevent unintended replacement of existing files.
- Apply outbound firewall rules that block metadata, loopback, link-local, and private network ranges as defense in depth.
- Permit only
