T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/generate.py:157
- Finding
- Unrestricted URL Fetching Enables Server-Side Request Forgery## Vulnerability Details **File Location**: `scripts/generate.py`, lines 157-235 and 432-455 **Vulnerability Type**: Server-Side Request Forgery through user-controlled URLs and redirects **Risk Level**: High ### Vulnerable Code ```python def download_to_file(client: httpx.Client, url: str, dest: Path) -> bool: """Download a URL to a local file. Returns True on success.""" try: headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", "Accept": "image/*,*/*;q=0.8", } response = client.get(url, headers=headers, follow_redirects=True, timeout=20.0) if response.status_code == 200 and len(response.content) > 1000: content_type = response.headers.get("content-type", "") if "image" in content_type or "octet" in content_type or len(response.content) > 5000: dest.parent.mkdir(parents=True, exist_ok=True) dest.write_bytes(response.content) size_kb = len(response.content) / 1024 print(f" ✓ Downloaded: {dest.name} ({size_kb:.0f}KB)", flush=True) return True except Exception as e: print(f" ✗ Download failed: {e}", flush=True) return False def fetch_product_image(client: httpx.Client, product_url: str, dest: Path) -> bool: """Try to find and download the main product image from a product page.""" try: from bs4 import BeautifulSoup except ImportError: print(" ⚠ beautifulsoup4 not available for product image extraction", flush=True) return False print(" Fetching product page for main image...", flush=True) try: headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", "Accept": "text/html,*/*", } response = client.get(product_url, headers=headers, follow_redir ...[truncated 4779 chars]
- Remediation
- ## Remediation Suggestions 1. Accept only `https` URLs unless another scheme is explicitly required. 2. Resolve every hostname before connecting and reject loopback, private, link-local, multicast, unspecified, and reserved IPv4 and IPv6 addresses. 3. Disable automatic redirects or validate the scheme, hostname, port, and resolved address of every redirect hop. 4. Apply identical validation to product URLs, `og:image` URLs, HTML image URLs, and generated output URLs. 5. Use an outbound allowlist or isolated fetching proxy where practical. 6. Stream responses and enforce strict limits on response size, content type, and download duration. 7. Validate actual image structure using an image-decoding library rather than trusting headers or file size. 8. Require explicit user confirmation before uploading automatically fetched content to ComfyDeploy. 9. Document that the product URL and selected assets are transmitted to a third-party cloud service. 10. Ensure the remote ComfyDeploy deployment applies equivalent SSRF controls to its server-side scraper.
