T09 · Insecure Skill Coding Practices
- Location
scripts/generate-image.py:177- Finding
Unrestricted Download from a Server-Supplied URL Enables SSRF and Resource Exhaustion
- Content
View full analysis
= 300 and resp.status < 400: location = resp.headers.get('Location') if location: return download_file(location, dest_path) if resp.status != 200: raise RuntimeError(f'Download failed with status {resp.status}') with open(dest_path, 'wb') as f: shutil.copyfileobj(resp, f) return dest_path ``` ```python async def _download(): print(f'{tag}Downloading image to {filepath}...') await asyncio.to_thread(download_file, result['url'], filepath) print(f'{tag}Image saved: {filepath}') return filepath return await with_retry(_download, max_retries=MAX_RETRIES, context=tag) ``` ### Technical Analysis The image URL received from the RunningHub API is passed directly to `urllib.request.urlopen()` without validating its scheme, hostname, resolved IP address, port, or final redirect destination. The implementation does not: - Require HTTPS for downloaded images. - Restrict downloads to approved RunningHub or CDN domains. - Reject loopback, link-local, private, multicast, or reserved IP addresses. - Revalidate DNS resolution immediately before connecting. - Validate every redirect destination. - Set a download timeout. - Limit the maximum number of downloaded bytes. - Verify that the response ...[truncated 2662 chars]- Remediation
View remediation
