T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/sitemap_gen.py:79
- Finding
- Unrestricted Network Targets and Redirects Permit Server-Side Request Forgery## Vulnerability Details **File Location**: `scripts/sitemap_gen.py`, lines 79 and 160–164 **Vulnerability Type**: Server-Side Request Forgery (SSRF) through unrestricted URLs and redirects **Risk Level**: Medium ### Vulnerable Code ```python resp = requests.get(url, headers=headers, timeout=timeout, allow_redirects=True) ``` The initial URL validation does not restrict destinations or URL schemes: ```python # Validate URL parsed = urlparse(args.url) if not parsed.scheme or not parsed.netloc: print("ERROR: Invalid URL. Include scheme (https://example.com)", file=sys.stderr) sys.exit(1) ``` ### Technical Analysis The crawler accepts any URL containing a scheme and network location. It does not explicitly restrict the scheme to HTTP or HTTPS, resolve and inspect the destination address, or reject loopback, private, link-local, reserved, and cloud metadata addresses. Furthermore, `allow_redirects=True` causes `requests` to follow redirects without validating each redirect destination. Consequently, an apparently safe public URL can redirect the crawler to an internal service. The same-domain check applied to discovered HTML links does not protect the request that has already followed the redirect. This creates an SSRF condition whenever an untrusted party can influence the starting URL or the redirect behavior of a crawled server. ### Attack Path 1. An attacker supplies a public HTTP or HTTPS URL to the user or Agent. 2. The crawler accepts the URL because it has a scheme and network location. 3. The attacker-controlled public server returns an HTTP redirect to a loopback, private-network, link-local, or cloud metadata address. 4. `requests.get(..., allow_redirects=True)` follows the redirect automatically. 5. The crawler issues a GET request to the internal destination from the privileges and network context of the host running the skill. 6. The internal endpoint may disclose information throug ...[truncated 873 chars]
- Remediation
- ## Remediation Suggestions 1. Explicitly allow only `http` and `https` URL schemes. 2. Resolve the destination hostname before every request and reject loopback, private, link-local, multicast, unspecified, and reserved IP address ranges. 3. Disable automatic redirects and process redirects manually. 4. Resolve and validate the destination of every redirect before following it. 5. Protect against DNS rebinding by ensuring the validated address is the address actually used for the connection. 6. Block known metadata destinations, including link-local cloud metadata addresses. 7. Consider requiring an explicit operator option before private-network crawling is permitted. 8. Apply outbound firewall or proxy restrictions so the crawler cannot access sensitive internal services.
