T09 · Insecure Skill Coding Practices
- Location
scripts/fetch_sitemap.py:33- Finding
Server-Side Request Forgery Through Unvalidated Sitemap and Nested Sitemap URLs
- Content
View full analysis
list[str]: req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) Chrome/126.0"}) with urllib.request.urlopen(req, timeout=timeout) as r: body = r.read().decode("utf-8", errors="replace") locs = re.findall(r"\s*(.*?)\s*", body, re.S) # Handle sitemap index (nested sitemaps) - one level deep if len(locs) > 0 and all(l.endswith((".xml", ".xml.gz")) for l in locs): nested = [] for sub in locs[:20]: try: req2 = urllib.request.Request(sub, headers={"User-Agent": "Mozilla/5.0"}) with urllib.request.urlopen(req2, timeout=timeout) as r2: body2 = r2.read().decode("utf-8", errors="replace") nested.extend(re.findall(r"\s*(.*?)\s*", body2, re.S)) except Exception: continue locs = nested ``` The initial sitemap URL and every nested `` value are passed directly to `urllib.request.urlopen`. There is no validation of the URL scheme, resolved IP address, destination port, redirect target, or relationship between a nested sitemap and the original client domain. `urllib` also follows redirects by default. Consequently, even when `run.sh` constructs an initial HTTPS URL, a remote server can redirect the request to an internal or link-local destination. Nested sitemap entries can directly reference internal services or non-HTTP schemes supported by the runtime. Fetching a client-controlled sitemap is necessary for the declared functionality, but unrestricted access to arbitrary destinations is not. ### Attack Path 1. An attacker supplies a client website they control, or compromises the configured website. 2. The ...[truncated 1254 chars]- Remediation
View remediation
