T09 · Insecure Skill Coding Practices
- Location
scripts/imagegen.py:263- Finding
Unvalidated API-Controlled Result URL Enables Arbitrary Network Requests
- Content
View full analysis
Vulnerability Details
File Location:
scripts/imagegen.py:263-268, 352-357
Vulnerability Type: Server-Side Request Forgery through an untrusted result URL
Risk Level: MediumVulnerable Code:
python def download_file(url, out_path, timeout=300): """Stream a file download and display progress.""" print(f"[download] {out_path.name}") try: resp = requests.get(url, stream=True, timeout=timeout) resp.raise_for_status()python for i, item in enumerate(succeeded): result_url = item.get("resultUrl") if not result_url: continue ext = ".mp4" if "video" in task_type.lower() else ".png" filename = f"{task_type}_{task_id}_{i+1}{ext}" out_path = out_dir / filename download_file(result_url, out_path)Technical Analysis
The
resultUrlvalue is obtained from a remote API response and passed directly torequests.getwithout validating its scheme, hostname, resolved IP address, port, or redirect destination. The Requests library follows redirects by default for GET requests.If the AI Hive API, an upstream task provider, or the relevant API response is compromised, an attacker can cause the client to issue a GET request to an arbitrary destination reachable from the user's machine. Potential destinations include loopback services, private network hosts, cloud metadata endpoints, and link-local services.
Attack Path
- An attacker gains the ability to influence a generation-task API response.
- The attacker places an arbitrary URL in the completed task item's
resultUrl, such as an internal HTTP service or a redirector leading to a private address. - The client identifies the task item as completed and calls
download_file. requests.getconnects to the attacker-selected destination and follows redirects without destination validation.- The response body is written to the configured output directory.
...[truncated 623 chars]
- Remediation
View remediation
Remediation Suggestions
- Permit only HTTPS result URLs.
- Maintain an explicit allowlist of approved object-storage hostnames.
- Reject URLs containing embedded credentials, unexpected ports, fragments, or unsupported schemes.
- Resolve destination hostnames and reject loopback, private, link-local, multicast, reserved, and unspecified IP ranges.
- Disable automatic redirects or validate every redirect target against the same policy.
- Apply download-size limits in addition to the existing timeout.
- Prefer receiving an opaque media identifier from the API and resolving it through a trusted, fixed endpoint rather than accepting an arbitrary URL.
