T09 · Insecure Skill Coding Practices
- Location
scripts/full_workflow.py:88- Finding
Unvalidated Remote Media URLs Permit Server-Side Request Forgery and Resource Exhaustion
- Content
View full analysis
Vulnerability Details
File Location:
scripts/full_workflow.py, lines 88-93 and 141-146
Vulnerability Type: Unvalidated remote resource retrieval
Risk Level: MediumVulnerable Code
python image_url = result["data"][0]["url"] # Download image local_path = self.output_dir / f"scene_{scene_id}.jpg" img_response = requests.get(image_url, timeout=30) with open(local_path, "wb") as f: f.write(img_response.content)python video_url = status["content"]["video_url"] # Download video local_path = self.output_dir / f"scene_{scene_id}.mp4" video_response = requests.get(video_url, timeout=120) with open(local_path, "wb") as f: f.write(video_response.content)Technical Analysis
The workflow retrieves image and video URLs from Ark API responses and passes them directly to
requests.get()without validating the URL scheme, hostname, resolved IP address, redirect chain, response status, content type, or response size.requestsfollows redirects by default. Consequently, a compromised, malicious, or malformed upstream response could direct the process to loopback addresses, private network services, link-local cloud metadata endpoints, or other resources reachable from the host. Redirects can also be used to bypass a validation check if only the initial URL is inspected.The use of
response.contentbuffers the complete response in memory before writing it. No maximum download size or disk quota is enforced, allowing an unexpectedly large response to consume substantial memory and disk space. The downloaded content is also accepted as trusted media without checking its MIME type or file signature.Attack Path
- An attacker compromises the upstream API, influences an API response, or otherwise causes the returned
image_urlorvideo_urlto reference an attacker-controlled endpoint. - The attacker supplies a direct internal URL or an external URL that redirect ...[truncated 1546 chars]
- An attacker compromises the upstream API, influences an API response, or otherwise causes the returned
- Remediation
View remediation
Remediation Suggestions
- Permit only HTTPS media URLs from an explicit allowlist of expected Ark/CDN hostnames.
- Resolve the hostname before connecting and reject loopback, private, link-local, multicast, unspecified, and reserved IPv4 and IPv6 ranges.
- Disable automatic redirects with
allow_redirects=False, or validate every redirect target before following it. - Call
raise_for_status()before processing the response. - Use
stream=Trueand copy the response in bounded chunks while tracking a strict maximum byte count. - Enforce separate download limits appropriate for images and videos.
- Validate the
Content-Typeheader and verify the downloaded file's magic bytes before treating it as media. - Delete partial output files when validation or download fails.
- Apply connection and read timeouts separately, and cap the number of redirects.
- Repeat the same controls for both image and video download paths.
Example hardening pattern:
python with requests.get( validated_url, stream=True, timeout=(10, 30), allow_redirects=False ) as response: response.raise_for_status() validate_media_content_type(response.headers.get("Content-Type", "")) downloaded = 0 with open(local_path, "wb") as output: for chunk in response.iter_content(chunk_size=64 * 1024): downloaded += len(chunk) if downloaded > MAX_MEDIA_BYTES: raise ValueError("Media download exceeds the permitted size") output.write(chunk)
