T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/fetch_url.py:52
- Finding
- Unrestricted URL Fetching Enables Server-Side Request Forgery<![CDATA[ ## Vulnerability Details **File Location**: `scripts/fetch_url.py:52` **Vulnerability Type**: Server-Side Request Forgery (SSRF) **Risk Level**: High ### Vulnerable Code ```python response = requests.get(url, headers=headers, timeout=timeout, verify=False) ``` ### Technical Analysis The `url` argument is passed directly to `requests.get()` without validating its scheme, destination hostname, resolved IP address, port, or redirect chain. The URL can originate directly from a command-line argument or indirectly from a Baidu search result processed by `search_and_fetch.py`. The implementation does not prevent requests to: - Loopback addresses such as `127.0.0.1` or `::1` - RFC 1918 private networks - Link-local addresses such as `169.254.0.0/16` - Cloud instance metadata services - Internal DNS names and services - Reserved or multicast IP ranges - Redirect targets that resolve to restricted addresses - Nonstandard ports exposed only to the local host or private network A simple hostname allowlist check would not be sufficient because DNS rebinding, alternative IP representations, IPv6 addresses, and HTTP redirects could bypass it. Validation must occur after DNS resolution and after every redirect. ### Attack Path 1. An attacker supplies a URL to `scripts/fetch_url.py`, or influences a URL returned in the search results consumed by `scripts/search_and_fetch.py`. 2. The URL points directly to an internal service or redirects to an internal address. 3. `fetch_url()` passes the untrusted URL to `requests.get()` without destination validation. 4. The request is issued with the network privileges of the host running the Skill. 5. The internal service response is parsed and returned through console or JSON output. 6. Depending on the accessible endpoint, the attacker may obtain internal service information, cloud metadata, credentials, or other data unavailable from an external network. ### Impact Assessment Successful exploitation can cross netwo ...[truncated 435 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Accept only explicitly supported schemes, normally `http` and `https`. 2. Parse URLs using `urllib.parse.urlsplit()` and reject embedded credentials, malformed hostnames, and unexpected ports. 3. Resolve the hostname before connecting and reject every address that is loopback, private, link-local, multicast, reserved, or unspecified. 4. Explicitly block cloud metadata hosts and addresses, including link-local metadata endpoints. 5. Disable automatic redirects or validate every redirect destination using the same resolution and IP-range rules. 6. Protect against DNS rebinding by connecting only to validated resolved addresses while preserving correct TLS hostname verification. 7. Consider an explicit domain allowlist when the business workflow permits it. 8. Apply egress firewall rules so the process cannot reach internal or metadata networks. 9. Add tests covering IPv4, IPv6, encoded IP representations, internal DNS names, redirects, and DNS rebinding scenarios. ]]>
