T09 · Insecure Skill Coding Practices
- Location
scripts/check_links.py:39- Finding
Unrestricted Remote URL Requests Enable Server-Side Request Forgery
- Content
View full analysis
tuple[str, bool, str]: """Check if a remote URL is reachable.""" try: req = urllib.request.Request(url, method='HEAD', headers={ 'User-Agent': 'Mozilla/5.0 (compatible; LinkChecker/1.0)' }) urllib.request.urlopen(req, timeout=timeout) return url, True, 'OK' ``` The request is reached through URLs extracted directly from Markdown: ```python for url, line_num in extract_links(content, base_dir): if url.startswith(('http://', 'https://')): results.append((url, line_num, *check_remote_url(url, timeout))) ``` ### Technical Analysis The script sends HTTP requests to URLs extracted from potentially untrusted Markdown without validating the destination hostname, resolved IP address, port, or redirect target. Checking only that the string begins with `http://` or `https://` does not prevent requests to: - Loopback services such as `127.0.0.1` or `[::1]` - RFC 1918 private network addresses - Link-local addresses and cloud metadata services - Internal hostnames resolved by the local DNS environment - Public URLs that redirect to internal destinations - Services listening on unusual or sensitive ports `urllib.request.urlopen` follows supported HTTP redirects by default. Consequently, validating only the initial URL scheme would remain insufficient even if limited validation were added before constructing the request. The request uses `HEAD`, which may reduce response-body exposure but does not eliminate SSRF. A `HEAD` request can still reach internal services, reveal network accessibility through status or timing behavior, and trigger endpoint behavior on servers that do not implement method handling safely. ### Attack Path ...[truncated 1523 chars]- Remediation
View remediation
