T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/smart_download.py:98
- Finding
- Unrestricted URL Fetching Enables Server-Side Request Forgery## Vulnerability Details **File Location**: `scripts/smart_download.py`, lines 98-104; user-controlled URLs are loaded at lines 254-258 **Vulnerability Type**: Unrestricted outbound request / SSRF **Risk Level**: High ### Vulnerable Code ```python async with client.stream( "GET", url, headers=headers, timeout=self.timeout, follow_redirects=True ) as response: response.raise_for_status() ``` User input reaches this request through: ```python if Path(args.urls).exists(): urls = load_urls_from_file(args.urls) print(f"✓ 从文件加载 {len(urls)} 个 URL") else: urls = [url.strip() for url in args.urls.split(',') if url.strip()] print(f"✓ 从命令行加载 {len(urls)} 个 URL") ``` ### Technical Analysis The downloader accepts arbitrary user-supplied URLs and passes them to `httpx.AsyncClient.stream()` without validating the URL scheme, destination hostname, resolved IP address, or redirect targets. Redirect following is explicitly enabled. An attacker who can influence the URL list can direct the process toward loopback addresses, private network ranges, link-local services, or cloud instance metadata endpoints. An apparently public URL can also redirect to a prohibited internal address because each redirect destination is not independently validated. Custom request headers increase the sensitivity of unrestricted requests because user-provided header values are attached to requests made to attacker-selected destinations. ### Attack Path 1. An attacker supplies a URL such as one targeting a loopback, private-network, or link-local service. 2. Alternatively, the attacker supplies a public URL that redirects to an internal service. 3. The downloader makes the request and follows redirects without destination validation. 4. The internal response body is downloaded and saved under the configured output directory. 5. A user or downstream process may expose or consume the retrieve ...[truncated 408 chars]
- Remediation
- ## Remediation Suggestions - Permit only explicitly supported schemes, normally `https` and, if necessary, `http`. - Reject URLs containing embedded credentials or malformed host components. - Resolve destination hostnames before connecting and reject loopback, private, link-local, multicast, unspecified, and reserved IP ranges. - Repeat scheme, hostname, and resolved-address validation for every redirect. - Consider enforcing an explicit hostname allowlist when the expected download sources are known. - Apply outbound firewall or proxy controls so the process cannot reach metadata services or internal administrative networks. - Restrict which custom headers can be supplied and avoid forwarding sensitive headers across origins.
