T09 · Insecure Skill Coding Practices
- Location
scripts/generate.py:48- Finding
Unvalidated API-Supplied URLs Enable Arbitrary Network Requests and Unbounded Downloads
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate.py, lines 48-51, 98-101, 139, and 156
Vulnerability Type: Unrestricted server-supplied URL retrieval
Risk Level: MediumVulnerable Code
python if "data" in data: url = data["data"][0]["url"] print(f"图片生成成功: {url}") return urlpython if status == "completed": video_url = data.get("remixed_from_video_id") print(f"视频生成成功: {video_url}") return video_urlpython # Download the image resp = httpx.get(url) ext = "jpg" if b"JPEG" in resp.content else "png" file_path = output_dir / f"image_{int(time.time())}.{ext}" file_path.write_bytes(resp.content)python # Download the video print("正在下载视频...") resp = httpx.get(video_url) file_path = output_dir / f"video_{int(time.time())}.mp4" file_path.write_bytes(resp.content)Technical Analysis
The script trusts media URLs supplied by the remote API and passes them directly to
httpx.get. It does not validate the URL scheme, destination hostname, resolved IP address, or redirect destinations. It also does not configure network timeouts, verify successful HTTP status codes, stream downloads, or impose a maximum response size.Consequently, a compromised API service, manipulated API response, or other party able to control the returned URL could direct the script to request loopback, private, link-local, or otherwise sensitive network resources. Redirects may also lead from an initially acceptable host to a prohibited destination.
Because the response is loaded completely into memory and then written to disk, an attacker-controlled endpoint can return an extremely large or indefinitely slow response. This may consume memory, disk capacity, network bandwidth, or execution time.
Attack Path
- The user invokes image or video generation with a valid Agnes API key.
- An attacker compromises the upstream API, interferes w ...[truncated 1224 chars]
- Remediation
View remediation
Remediation Suggestions
- Require HTTPS and reject all other URL schemes.
- Allowlist the exact storage hostnames expected to serve generated media.
- Resolve destination hostnames and reject loopback, private, link-local, multicast, reserved, and unspecified addresses for both IPv4 and IPv6.
- Repeat destination validation after every redirect, or disable redirects entirely.
- Configure explicit connection, read, write, and pool timeouts.
- Call
raise_for_status()before processing response content. - Stream responses to disk rather than loading the complete body into memory.
- Enforce a strict maximum download size using both
Content-Length, when present, and a running byte counter. - Validate the returned content type and, where practical, verify the media format from trusted file signatures before saving it.
- Treat absent or malformed image and video URLs as API errors rather than passing them to the HTTP client.
