T09 · Insecure Skill Coding Practices
- Location
scripts/gen_image.py:105- Finding
Unvalidated Server-Provided Media URLs Permit Server-Side Request Forgery
- Content
View full analysis
Vulnerability Details
File Location:
scripts/gen_image.py:105-110;scripts/gen_video.py:134-139, 172-179
Vulnerability Type: Unvalidated remote URL retrieval / SSRF
Risk Level: MediumVulnerable Code
python # scripts/gen_image.py:105-110 for index, item in enumerate(data, start=1): url_value = item.get("url") file_path = out_dir / f"image-{int(time.time())}-{index}.png" req = urllib.request.Request(url_value, headers={"User-Agent": args.user_agent}) with urllib.request.urlopen(req) as res: file_path.write_bytes(res.read())python # scripts/gen_video.py:134-139 def download_video(url: str, path: pathlib.Path, timeout: int, user_agent: str, verbose: bool) -> None: req = urllib.request.Request(url, headers={"User-Agent": user_agent}, method="GET") if verbose: print(f"[debug] GET {url} -> {path}") with urllib.request.urlopen(req, timeout=timeout) as response: path.write_bytes(response.read())python # scripts/gen_video.py:172-179 video_url = (final.get("video") or {}).get("url") if not video_url: raise SystemExit(f"Completed response does not contain video url: {json.dumps(final)}") out_dir = ensure_dir(args.out_dir) extension = pathlib.Path(video_url).suffix or ".mp4" output_path = out_dir / f"video-{generation_id.split(':', 1)[0]}{extension}" download_video(video_url, output_path, args.timeout, args.user_agent, args.verbose)Technical Analysis
Both scripts trust media URLs returned by AIMLAPI and pass them directly to
urllib.request.urlopen. The code does not validate the URL scheme, destination hostname, resolved IP address, port, or redirect chain.Consequently, a malicious or compromised API response could direct the scripts to request loopback, link-local, private-network, cloud metadata, or other unintended resources. Redirects create the same risk even when the initial URL appe ...[truncated 1742 chars]
- Remediation
View remediation
Remediation Suggestions
- Accept only
httpsmedia URLs. - Maintain an explicit allowlist of AIMLAPI-approved media download hostnames.
- Resolve destination hostnames before connecting and reject loopback, private, link-local, multicast, reserved, and unspecified IP ranges for both IPv4 and IPv6.
- Disable automatic redirects or validate the scheme, hostname, port, and resolved address at every redirect hop.
- Reject URLs containing credentials and restrict destination ports to approved HTTPS ports.
- Apply a maximum response size and stream downloads in bounded chunks instead of calling
response.read()without a limit. - Apply the same validation helper consistently to both image and video downloads.
- Accept only
