import type { FetchLike } from "../handlers/HandlerRegistration.js"; import type { SecurityEvents } from "../incident/SecurityEvents.js"; import { EgressPolicy } from "./EgressPolicy.js"; export interface ResolvedAddress { readonly address: string; readonly family: 4 | 6; } /** Name resolution, injectable so a test can answer a name with any address. */ export type AddressResolver = (hostname: string) => Promise; export interface GuardedFetchOptions { readonly policy: EgressPolicy; readonly events: SecurityEvents; readonly maxResponseBytes: number; /** A transport to delegate to after the policy check; the `node:https` transport when absent. */ readonly transport?: FetchLike; readonly resolve?: AddressResolver; /** The executor's own ceiling on any one request, headers and body included. */ readonly timeoutMs?: number; /** Refuse every private and shared address too (EgressPolicy.addressRefused). */ readonly publicOnly?: boolean; /** * Whether a TLS failure is this process's own `EGRESS_REFUSED`, as it is * unless this says otherwise: a destination the operator named whose * handshake fails, or whose verified session breaks, is an attack until * shown otherwise. False is for a destination someone else chose, whose TLS * is theirs to fix: a refused handshake is thrown with its code, a broken * session with its own error, and the caller reports either as it sees fit. */ readonly reportTls?: boolean; } /** * A peer's alert refusing this side's certificate, which this process never * presents: `certificate_required` (TLS 1.3), `bad_certificate`, * `certificate_unknown`, `unknown_ca` or `access_denied`, as servers that do * not send the first send instead. Any of them says the peer refused the * handshake on its side, about a certificate that can only be this side's, * since this side had already verified the peer's: under TLS 1.3 it arrives * after this side's half of the handshake, but the peer's never completed, * so nothing was accepted. Under TLS 1.2 the usual refusal is a bare * handshake failure, which says no more than that. */ export declare const CLIENT_CERTIFICATE_REFUSED: RegExp; /** * The one way this process opens a connection. Every request is checked * against the sealed policy before a socket exists; a name is resolved once * and refused if it answers with an address the policy forbids; TLS is * verified against the destination's own anchor and pins; redirects are * never followed; the body is bounded and returned whole. What comes back * is a standard `Response`, which is what the gate, the verifier, the * Presence transport, and the handlers expect from a fetch. Every refusal * is a code on the security stream with the origin and nothing else. */ export declare class GuardedFetch { private readonly options; readonly fetch: FetchLike; private readonly agents; private readonly resolve; private readonly timeoutMs; constructor(options: GuardedFetchOptions); close(): void; private guarded; private request; /** Reads the whole body under the bound and builds the `Response` the caller expects. */ private collect; private inspectRedirect; /** Every refusal is an event with the origin and the code; the error carries the same and no more. */ private refuse; /** * A failure of the executor's own making is reported; the caller's abort * and the network's failures pass through. A handshake that failed is a * refusal, and nothing was sent: the peer's certificate did not verify, * or the peer refused this side, by refusing its certificate * (`EGRESS_TLS_CLIENT_CERT_REFUSED`) or otherwise. A TLS failure once the * peer was verified broke a connection that may have carried the request, * so it is not a refusal and its own error passes through; it is still * reported, as `EGRESS_TLS_BROKEN`, unless the caller reports TLS itself * (`reportTls: false`): records that break a verified session are an * attack until shown otherwise, and count toward the halt switch and the * refusal alerts as they did when they were called a rejected handshake. */ private classify; /** A refused handshake: on the security stream, unless the caller reports it itself. */ private refuseTls; private agentFor; /** Resolves once and connects only to what was resolved; one forbidden answer refuses the whole name. */ private lookupFor; /** Hostname verification as usual, then the pins: any certificate in the chain may match. */ private static identity; private static body; private static headers; private static abortReason; } //# sourceMappingURL=GuardedFetch.d.ts.map