/** * Browser-trust fence for this plugin's mutating routes. * * DSH applies the same fence to `/api`, but its implementation * (`packages/client/connection/src/api-request-trust.ts`) is package-internal * — it is not re-exported from `@deepseek-ai/dsh-client-connection`'s entry * point — so a plugin route has to carry its own copy rather than depend on a * private path. The logic below mirrors that module deliberately; keep them in * step if upstream changes. * * It defends the two confused-deputy paths a browser opens against a local * HTTP API: DNS rebinding (the Host header names the attacker's domain while * the socket reaches this server) and cross-site requests fired by a malicious * page. It is not an authentication layer. */ import type { IncomingHttpHeaders } from 'node:http'; /** The request facts the fence reads. */ export interface TrustRequest { readonly headers: IncomingHttpHeaders; } /** * Whether a normalized hostname names the local loopback authority. * @param hostname - a WHATWG URL hostname (IPv6 literals retain brackets). * @returns true for localhost, IPv6 loopback, or any IPv4 address in 127/8. */ export declare function isLoopbackHostname(hostname: string): boolean; /** * Decide whether a mutating request may act on this profile. * * @param request - the incoming request's headers. * @param trustedHosts - non-loopback authorities this deployment serves. * @returns true when the Host is ours and any browser markers are same-origin. */ export declare function isTrustedRequest(request: TrustRequest, trustedHosts: readonly string[]): boolean;