Heuristic:0xsline OpenChatCut SSRF Safe Fetch
| Knowledge Sources | |
|---|---|
| Domains | Security, Networking |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
SSRF-safe URL fetching with private IP blocking, DNS rebinding prevention via address pinning, bounded connect/headers timeouts, and redirect validation.
Description
OpenChatCut's `safePublicFetch` validates that a URL resolves to a public IP address before connecting, pins the resolved address to prevent DNS rebinding, blocks cloud metadata endpoints, and enforces separate connect and headers timeouts. The connect timeout (10s) covers TCP/TLS handshake; the headers timeout (30s) covers request start to response headers. A healthy download body is never cut off by either timer. Redirects are followed but each redirect target is re-validated for public addresses. Non-standard ports, credential URLs, and localhost/internal hostnames are rejected.
Usage
Use this heuristic when fetching media from user-supplied URLs (export media materialization, generated result download) or any server-side HTTP fetch of untrusted URLs. Apply it whenever the server fetches content referenced by user input to prevent SSRF attacks against internal services and cloud metadata endpoints.
The Insight (Rule of Thumb)
- Action: Resolve the hostname, validate every returned IP is public, pin the first public address for the actual connection, and block localhost/.local/.internal/metadata hostnames.
- Value: Connect timeout = 10s, Headers timeout = 30s, Max redirects = 5. Blocked: 10.x, 127.x, 169.254.x, 172.16-31.x, 192.168.x, fc00::/7, fe80::/10, cloud metadata hosts.
- Trade-off: Slightly slower fetch due to DNS resolution before connection; legitimate private-network media cannot be fetched (by design).
- Compatibility: Works through outbound proxies; the CONNECT tunnel targets the pinned address so the public check still governs.
Reasoning
DNS rebinding attacks resolve a hostname to a public IP during validation, then to a private IP during the actual connection. Pinning the resolved address defeats this. Cloud metadata endpoints (`metadata.google.internal`, `metadata.azure.internal`) expose instance credentials to SSRF attackers. The two-phase timeout (connect vs headers) was added because a blocked host behind a proxy can look connected (proxy answers CONNECT) but then never respond — the OS TCP timeout (~75s on macOS) would serially stall an entire batch under a 30-minute overall abort.