T09 · Insecure Skill Coding Practices
- Location
scripts/media_gen_client.py:105- Finding
Unrestricted Retrieval of Server-Supplied Media URLs
- Content
View full analysis
Vulnerability Details
File Location:
scripts/media_gen_client.py, lines 105-122; invoked with API-supplied URLs at lines 382-385, 407-410, and 450-454
Vulnerability Type: Unvalidated outbound request and unbounded file download
Risk Level: MediumVulnerable Code
python def _download_to_file(url: str, out_path: str, timeout_s: int = 300) -> Dict[str, Any]: """ Download a (possibly signed) URL to local file. Designed for OSS signed URLs returned by video generation tasks. """ os.makedirs(os.path.dirname(out_path) or ".", exist_ok=True) req = urllib.request.Request(url, headers={"User-Agent": "AIsa-Media-Gen/1.0"}) try: with urllib.request.urlopen(req, timeout=timeout_s) as resp, open(out_path, "wb") as f: total = 0 while True: chunk = resp.read(1024 * 1024) # 1MB if not chunk: break f.write(chunk) total += len(chunk) return {"success": True, "saved_to": out_path, "bytes": total} except Exception as e: return {"success": False, "error": str(e), "url": url, "saved_to": out_path}Representative call sites automatically pass URLs extracted from upstream responses:
python out_path = args.out or _safe_filename("png") dl = _download_to_file(urls[0], out_path) _print_json({"success": dl.get("success", False), "route": route, "model": args.model, "url": urls[0], "saved_to": out_path, "images_returned": len(urls), "download": dl})python if video_url: out_path = args.out or _safe_filename("mp4") dl = _download_to_file(video_url, out_path) resp = {**resp, "download": dl}Technical Analysis
The client trusts media URLs returned by the remote API and passes them directly to
urllib.request.urlopen. It does not validate:- The URL scheme or require HTTPS.
- The destination hostname or resolved IP address.
- Whether ...[truncated 2035 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse every returned URL before use and permit only
httpsURLs. - Allowlist documented media-storage hostnames where operationally possible.
- Resolve the hostname and reject loopback, private, link-local, multicast, unspecified, and reserved addresses for both IPv4 and IPv6.
- Disable automatic redirects or validate every redirect target using the same scheme, hostname, and IP-address controls.
- Enforce an expected media content type, such as
image/*orvideo/*, before writing the response. - Enforce a configurable maximum download size using both
Content-Lengthand a streaming byte counter. - Download into a temporary file and atomically rename it only after successful validation and completion.
- Delete partial files when downloads fail.
- Consider requiring explicit user confirmation before downloading from a host outside an approved media-host allowlist.
- Parse every returned URL before use and permit only
