T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/geo_audit.py:24
- Finding
- Unrestricted Server-Side Request Forgery Through User-Controlled Audit Targets<![CDATA[ ## Vulnerability Details **File Location**: `scripts/geo_audit.py:24-49` and `scripts/geo_audit.py:369-376` **Vulnerability Type**: Server-Side Request Forgery (SSRF) **Risk Level**: High ### Complete Vulnerable Code ```python def __init__(self, domain, timeout=10, delay=0, user_agent=None): self.domain = domain.replace('https://', '').replace('http://', '').rstrip('/') self.base_url = f"https://{self.domain}" self.timeout = timeout self.delay = delay self.results = { "site": self.domain, "timestamp": datetime.utcnow().isoformat() + "Z", "score": 0, "total": 29, "grade": "F", "dimensions": [] } self.headers = { 'User-Agent': user_agent or 'GEO-Audit-Bot/1.0 (Research Purpose)' } def fetch(self, path='', full_url=None): """Fetch a URL with error handling.""" url = full_url or urljoin(self.base_url, path) try: time.sleep(self.delay) resp = requests.get( url, headers=self.headers, timeout=self.timeout, allow_redirects=True ) return resp except Exception as e: return None ``` ```python def check_https(self): """Check 4.2: HTTPS enforced.""" try: http_resp = requests.get( f"http://{self.domain}", timeout=self.timeout, allow_redirects=False ) if http_resp.status_code in [301, 302] and 'https' in http_resp.headers.get('Location', ''): return {"check": "HTTPS enforced", "status": "pass", "notes": "HTTP redirects to HTTPS"} except: pass return {"check": "HTTPS enforced", "status": "pass", "notes": "Site uses HTTPS"} ``` ### Technical Analysis The command-line `domain` value is directly converted into HTTP and HTTPS request targets. The implementation does not validate the parsed hostname, port, resolved IP address, or URL authority before issuing requests. Consequently, ...[truncated 1948 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Parse targets with `urllib.parse.urlsplit()` and accept only explicit `http` or `https` schemes. 2. Reject URLs containing user information, malformed authorities, fragments, or ports outside an approved policy. 3. Resolve all destination hostnames before connecting. 4. Reject every resolved IPv4 and IPv6 address that is loopback, private, link-local, multicast, reserved, unspecified, or otherwise non-global. 5. Explicitly block common cloud metadata destinations and hostnames. 6. Disable automatic redirects or validate the hostname and resolved addresses of every redirect destination before following it. 7. Defend against DNS rebinding by ensuring the validated address is the address used for the connection. 8. Apply outbound network firewall rules so the audit process cannot contact internal or metadata networks. 9. Add maximum response-size and redirect-count limits. 10. If the tool is exposed through an API, maintain an allowlist of auditable public domains and require authorization for every audit. ]]>
