import { type ClientRecord } from "./records.js"; import type { SecureStore } from "./storage.js"; /** * A client defined on the server, for clients that can use neither a client * ID metadata document nor dynamic client registration. */ export interface OAuthProxyClient { /** Client identifier that the client sends to `/authorize` and `/token`. */ clientId: string; /** Exact redirect URIs. On loopback (`http://127.0.0.1`) any port matches. */ redirectUris: readonly string[]; /** Name shown on the consent page. */ clientName?: string; } /** @internal Whether a redirect URI is an HTTP loopback URI (RFC 8252 7.3). */ export declare function isLoopbackRedirect(uri: string): boolean; /** * @internal Checks one redirect URI against the proxy's rules: HTTPS, HTTP * only on loopback, or a private-use scheme for native apps. Returns an * error message, or `undefined` when the URI is acceptable. */ export declare function redirectUriProblem(uri: unknown): string | undefined; /** * @internal Matches a requested redirect URI against registered ones: * exactly, except that a loopback URI may use any port (RFC 8252 7.3). */ export declare function matchRedirectUri(requested: string, registered: readonly string[]): boolean; /** * @internal Metadata-document clients that may connect: exact document URLs * and whole origins. `undefined` lets any client connect. */ export interface ClientAllowlist { urls: Set; origins: Set; } /** * @internal Validates the `clients` option: metadata-document URLs and * origins go to the allowlist, and client objects become configured clients. */ export declare function configuredClients(clients: readonly (string | OAuthProxyClient)[] | undefined): { byId: Map; allow: ClientAllowlist | undefined; }; /** @internal Whether a client_id is a CIMD URL: https with a non-root path. */ export declare function isCimdClientId(clientId: string): boolean; /** @internal Result of a registration request. */ export type RegistrationResult = { ok: true; client: ClientRecord; response: Record; } | { ok: false; error: string; description: string; }; /** * @internal Registers a public client (RFC 7591). The proxy issues no client * secret: every client authenticates with PKCE only. */ export declare function registerClient(store: SecureStore, body: unknown): Promise; /** @internal Lookup settings for {@link resolveClient}. */ export interface ClientResolver { store: SecureStore; configured: Map; allow: ClientAllowlist | undefined; dcr: boolean; fetchCimd: (url: string) => Promise; /** * Client ID of the OAuth app at the provider. The 1.x `oauthProxy` * answered every registration with it, so clients signed in before the * upgrade still send it. While `dcr` is on, it is treated as a client * registered with the redirect URI of the request. */ upstreamClientId: string; } /** * @internal Whether a client_id may connect under the current settings, * without fetching or reading anything. Token requests and access-token * checks use it, so that removing a client from `clients` or turning off * registration ends its existing sign-ins too. */ export declare function isClientAdmitted(resolver: Pick, clientId: string): boolean; /** * @internal Resolves a client_id: a CIMD URL first, then a configured * client, then a registered one. Returns an error message when the client * is unknown or not allowed. * * `redirectUri` is the one the request names. A client from the 1.x proxy * (see {@link ClientResolver.upstreamClientId}) has no stored record, so it * resolves to a record for that redirect URI alone. That admits no more * than registration does, which takes any client's redirect URIs. */ export declare function resolveClient(resolver: ClientResolver, clientId: string, redirectUri?: string | null): Promise; /** * @internal Creates a CIMD fetcher with a small in-process cache. With a * `resolver` loader, the host must resolve only to public addresses, and a * runtime without a resolver refuses every document. `false` skips the * check, for a custom `fetch` that enforces its own network policy. * * When the host is checked and `transport` loads one (Node.js and Bun), the * request connects only to the checked addresses. Elsewhere `fetchImpl` * resolves the host again, which leaves a small DNS-rebinding window. */ export declare function createCimdFetcher(fetchImpl: typeof globalThis.fetch, resolver: (() => Promise) | false, transport?: () => Promise): (url: string) => Promise; /** @internal A `lookup` for `node:https` that answers from a fixed list. */ export type PinnedLookup = (hostname: string, options: { all?: boolean; }, callback: (error: Error | null, address: string | { address: string; family: number; }[], family?: number) => void) => void; /** The parts of a `node:http` response that {@link requestPinned} uses. */ interface PinnedResponse { statusCode?: number | undefined; headers: Record; destroy(): unknown; } /** * @internal The parts of `node:https` and `node:stream` that * {@link createCimdFetcher} uses to connect to checked addresses only. */ export interface PinnedTransport { /** `https.request`. */ request(url: URL, options: { headers: Record; signal: AbortSignal; lookup: PinnedLookup; }, onResponse: (response: PinnedResponse) => void): { on(event: "error", listener: (error: Error) => void): unknown; end(): unknown; }; /** `Readable.toWeb`. */ toWeb(response: PinnedResponse): ReadableStream; } /** * @internal Loads `node:https` once on Node.js and Bun, where its `lookup` * option is honored, else `undefined`. Deno and Cloudflare Workers also * have `node:https`, but are not known to honor `lookup`. */ export declare function defaultPinnedTransport(): Promise; /** @internal Resolves a hostname to the IP addresses it points to. */ export type HostResolver = (hostname: string) => Promise; /** * @internal Refuses hosts that resolve to private, loopback, link-local, or * otherwise non-public addresses (SSRF). Without a `resolve`, only an IP * literal can be checked, so any other host is refused: failing open would * let a metadata-document URL reach the server's private network. */ export declare function assertPublicHost(hostname: string, resolve: HostResolver | undefined): Promise; /** * @internal {@link assertPublicHost}, returning the checked addresses (the * address itself for an IP literal) so the request can connect to them. */ export declare function resolvePublicAddresses(hostname: string, resolve: HostResolver | undefined): Promise; /** * @internal Picks a resolver from a loaded `node:dns` module, or returns * `undefined` when it has none. * * Node.js, Bun, and Deno use `lookup`, which resolves as `fetch` does * (getaddrinfo, including the hosts file). Cloudflare Workers is the * exception: its `node:dns` (with `nodejs_compat`) implements `resolve4` * and `resolve6` over DNS over HTTPS but throws "Not implemented" from * `lookup`, and a Worker has no hosts file for `lookup` to honor, so its A * and AAAA records are the addresses to check. * * @param dns - The `node:dns` module namespace. * @param userAgent - The runtime's `navigator.userAgent`. */ export declare function hostResolverFrom(dns: unknown, userAgent: string | undefined): HostResolver | undefined; /** * @internal Loads the runtime's resolver once: from `node:dns` where the * runtime has it, else `undefined`, which refuses metadata documents. */ export declare function defaultHostResolver(): Promise; /** @internal Whether an IP address is not publicly routable. */ export declare function isPrivateAddress(address: string): boolean; export {};