Expand description
SSRF (Server-Side Request Forgery) protection for URL-fetching tools.
Resolves each URL’s hostname to its IPs and blocks targets that point at
private/internal/cloud-metadata addresses. Inspired by the Python
url_safety.py in nousresearch/hermes-agent, with Rust-native resolution
semantics.
Limitations:
- DNS rebinding (TOCTOU): an attacker-controlled DNS server with TTL=0 can return a public IP for the pre-flight check and then a private IP on the actual connect. Mitigating this requires connection-level validation (e.g. a socket-bound resolver or an egress proxy). This module performs pre-flight checks only.
- Redirect-based bypass is caller-responsibility — callers that follow redirects themselves should re-validate each hop.
Functions§
- check_
raw_ url_ private_ ip - Pre-flight SSRF check for a raw URL string. Convenience wrapper that parses the URL first.
- check_
url_ private_ ip - Pre-flight SSRF check for an already-parsed URL. Returns
Err(message)when the URL targets an address that should be blocked. - is_
blocked_ ip - Returns true if the IP address belongs to a range that SSRF guards should reject. Combines stdlib predicates with explicit CGNAT + extra-safe link-local handling.
- ssrf_
redirect_ policy - A reqwest redirect policy that re-validates each hop against the SSRF
guard. Use with
reqwest::ClientBuilder::redirect(policy)to catch redirects inside third-party SDKs or forwarded requests that would otherwise bypass the manual redirect loop inweb_fetch.