T09 · Insecure Skill Coding Practices
- Location
scripts/image.py:157- Finding
Unrestricted URL Fetch and Arbitrary File Write
- Content
View full analysis
str: """ 下载图片到本地 Args: image_url: 图片URL output_path: 保存路径 Returns: 保存的文件路径 """ response = requests.get(image_url, timeout=60) response.raise_for_status() with open(output_path, "wb") as f: f.write(response.content) return output_path ``` ### Technical Analysis The `download_image()` function accepts a URL and output path without applying security restrictions to either value. The URL is passed directly to `requests.get()`. The function does not: - Restrict requests to HTTPS. - Enforce an allowlist of trusted image hosts. - Reject loopback, private, link-local, or reserved IP addresses. - Revalidate the destination after DNS resolution. - Disable or validate HTTP redirects. - Confirm that the response contains an image. - Limit the downloaded response size. - Stream the response incrementally. Consequently, an attacker who controls `image_url` can make the process issue requests to services accessible from its execution environment. Potential targets include localhost services, private-network systems, and cloud instance metadata endpoints. The response is loaded into memory through `response.content` and then written to the caller-supplied `output_path`. The path is not constrained to a designated output directory, normalized against an allowed root, or checked for symlink and overwrite conditions. An attacker can therefore replace any file writable by the process with the fetched response. Although normal image generation obtains the download URL from the MiniMax API response, `SKILL.md` documents `download_image(image_url, output_path)` as a directly available function. Both ...[truncated 1988 chars]- Remediation
View remediation
