T09 · Insecure Skill Coding Practices
- Location
scripts/download_image.py:134- Finding
Unrestricted URL Fetching Enables Server-Side Request Forgery
- Content
View full analysis
str: """Download image from Discord (direct URL).""" resp = requests.get(url) resp.raise_for_status() with open(output_path, "wb") as f: f.write(resp.content) return output_path ``` ```python def download_direct_url(url: str, output_path: str, headers: dict = None) -> str: """Download image from direct URL.""" resp = requests.get(url, headers=headers or {}) resp.raise_for_status() with open(output_path, "wb") as f: f.write(resp.content) return output_path ``` ```python parser.add_argument("--url", help="Direct image URL (for Discord or any direct link)") ``` ### Technical Analysis The downloader accepts an arbitrary URL and passes it directly to `requests.get`. It does not validate the URL scheme, hostname, port, resolved IP address, or redirect destination. Although direct attachment downloads are necessary for some supported platforms, accepting “any direct link” exceeds the minimum privilege required. A Discord-specific operation should normally be restricted to approved Discord CDN domains. The generic mode permits the process to access any address reachable from the host, including loopback interfaces, private networks, link-local services, and cloud metadata endpoints. The default redirect behavior of `requests` creates an additional bypass: even if a caller initially supplies a public URL, that server can redirect the request to an internal destination. ### Attack Path 1. An attacker sends or supplies a crafted image URL. 2. The Agent invokes the downloader with `--url` or the Discord platform mode. 3. The script se ...[truncated 722 chars]- Remediation
View remediation
