/** * SSRF guard for the TS edge client (F-7). * * Mirrors `edge-client/src/network/ws_client.rs::is_private_ip`, * `is_valid_scheme`, and `ssrf_safe_redirect_policy`. * * Background: the relay can dispatch a `browser_fetch` action to the * edge client (used for "open this URL in the headless browser on the * device"). A compromised or misconfigured relay could use this to * probe internal services on the device's network (AWS IMDS at * 169.254.169.254, localhost, RFC1918, etc.). The Rust client refuses * any URL that resolves to a private/loopback/link-local IP and only * allows http(s)://. * * The TS client has no such guard today. S-07 ports the guard so when * a future TS revision adds the `browser_fetch` handler, the guard * already exists and is wired in (defense-in-depth — prevents the * zero-day where someone adds the handler without the guard). * * Pure decision logic. No I/O. The DNS lookup (which can TOCTOU) is * handled at the call site (`ssrfSafeFetch`). */ /** Decision for whether a URL is safe to fetch. */ export type SsrfDecision = { readonly kind: 'Allow'; } | { readonly kind: 'Refuse'; readonly reason: string; }; /** * True if `ip` is a private/loopback/link-local/unspecified IPv4 or IPv6 * address that should never be reached from a browser_fetch action. * Mirrors `edge-client/src/network/ws_client.rs::is_private_ip`. */ export declare function isPrivateIp(ip: string): boolean; /** * True if `url` uses http:// or https:// (no file://, no ws://, etc.). */ export declare function isValidScheme(url: string): boolean; /** * True if `url` is safe to fetch from a browser_fetch action: * - valid http(s) scheme * - host is parseable * - host is NOT a private IP (literal or DNS-resolvable) * * NOTE: this is a synchronous pure check on the URL STRING. DNS resolution * (which can TOCTOU) happens via the optional `dnsLookup` callback. */ export declare function isSsrfSafeUrl(url: string, dnsLookup?: (host: string) => string[]): SsrfDecision; /** * Convenience wrapper for the `browser_fetch` handler. * * SECURITY NOTE (post-fix review 2026-07-14, G-8): The DNS lookup + the * future `fetch()` are vulnerable to a DNS-rebinding TOCTOU window — * the attacker returns a public IP for the guard check, then returns a * private IP when `fetch()` actually resolves the hostname. The Rust * reference has the same TOCTOU and explicitly documents it as a known * limitation. Full mitigation would require a custom DNS resolver that * returns a single IP and `net.connect({..., family: 4, localAddress: * })` to force the connection. DEFERRED to a follow-up PR. * * When implementing the actual fetch in a follow-up, do: * 1. resolve the host ONCE (get the single IP), * 2. pass that IP as the connection address to fetch's underlying socket, * 3. set the Host header to the original hostname (so SNI/cert * validation still works against the public hostname). */ export declare function guardBrowserFetchUrl(url: string, dnsLookupAddresses: (host: string) => string[]): SsrfDecision;