/** * @file SSRF guard for operator- or issuer-supplied URLs — `assertSafeHttpUrl` * parses a raw URL, rejects non-HTTP(S) schemes, refuses hosts that resolve * to loopback / private / link-local ranges (cloud metadata, redis, internal * services), and requires `https:` for every public host so credentials never * cross the network in cleartext. A server that fetches a URL it did not * author (an OAuth issuer, an introspection endpoint advertised in its * metadata, a webhook target) runs the candidate through this before the * request leaves the box. `allowLocalhost` is the one path that still accepts * plaintext `http:`, and only for a loopback host. */ import type { AssertSafeHttpUrlOptions } from './types.js'; /** * Parse `rawUrl` and assert it is safe to fetch server-side, returning the * parsed `URL`. Throws when the value does not parse, uses a scheme other than * `http:` / `https:`, resolves to a loopback / private / link-local host, or is * a public host reached over plaintext `http:`. A public host must be `https:` * because these URLs carry bearer tokens and client credentials, which `http:` * puts on the wire in cleartext for any network observer. Set `allowLocalhost` * to permit `localhost` / `127.0.0.1` / `::1` — over `http:` — for local-stack * development. `label` names the subject in the thrown message. * * @example * ;```typescript * assertSafeHttpUrl('https://api.example.com', { label: 'OAuth issuer' }) * // → URL { href: 'https://api.example.com/' } * * assertSafeHttpUrl('http://api.example.com') * // → throws: must use https: for a public host * * assertSafeHttpUrl('http://localhost:3000', { allowLocalhost: true }) * // → URL { href: 'http://localhost:3000/' } * * assertSafeHttpUrl('http://169.254.169.254/latest/meta-data') * // → throws: resolves to a private/loopback host * * assertSafeHttpUrl('ftp://example.com') * // → throws: must use http(s) * ``` * * @security-disposition Published API — socket-cli's * packages/cli/src/util/url/safe-endpoint.mts wraps this as its SSRF gate. */ export declare function assertSafeHttpUrl(rawUrl: string, options?: AssertSafeHttpUrlOptions | undefined): URL;