/** * Auth plugin for remote dsh Web access with front-end login/register. * * Responsibilities: * - Refuse to start with `--host 0.0.0.0` unless credentials can be managed. * - Serve a login/register page at `/login`. * - Provide session management (signed cookies; expiry configurable in the settings tab, default 14 days). * - Protect every registered route by wrapping the webserver's registration. * - Bridge dsh 0.1.2's native browser authentication: mint the native * `dsh-auth-*` cookie for callers our session layer already trusts, so a * `dsh_sid` session (or a genuine loopback request) clears the upstream * `isAuthenticated` fence without exposing the launch-token URL flow. * - Provide a `webAuth` service that downstream transport layers can use. * * Wire-level enforcement: * The plugin wraps `ctx.webServer.register` to inject a session check into * every registered route (except `/login` and `/api/auth/*`). The * `connection` row must inject `webAuth` so it activates after this plugin. * * Trust model (dsh 0.1.2): * Upstream now runs its own browser auth (`browser-auth.ts`): the `/api` * fence is `trust fence (403) + native-cookie check (401)` with NO loopback * exemption, and `index.html` is gated the same way. A valid `dsh_sid` * session — or a genuine loopback request (loopback peer address *and* * loopback `Host`, see `isTrustedOrigin`) — passes our wrapper, and the * wrapper mints the native cookie on the fly (a 200 bounce document * with a meta refresh for page navigations, a single 303 for * non-navigation GET/HEAD) so the very next request satisfies upstream. * The bind * address alone is not a trust signal: binding to 127.0.0.1 behind a * reverse proxy still serves remote clients, whose forwarded `Host` names * the public domain. */ import type { Context } from '@deepseek-ai/cordis'; import z from '@deepseek-ai/schemastery'; import type { IncomingMessage, ServerResponse } from 'node:http'; declare module '@deepseek-ai/cordis' { interface Context { webAuth?: WebAuthService; } interface Events { /** * Admit or wrap an authenticated shared API request (dsh-client-connection's * `/api` bridge). Same shape as the upstream declaration in * `packages/client/connection/src/index.ts`; declared locally because this * plugin does not depend on that package. Dispatched as a waterfall AFTER * upstream admission (trust fence + native-cookie check); a listener that * does not call `next()` vetoes the remaining chain, including the bridge. */ 'connection/request'(request: IncomingMessage, response: ServerResponse, next: () => Promise): Promise; } } /** Stable Cordis plugin name. */ export declare const name = "web-auth"; /** Services required before the auth policy can be installed. */ export declare const inject: string[]; /** Auth plugin configuration (no static config needed; credentials are stored on disk). */ export interface Config { } export declare const Config: z; /** The auth service provided to transport/tool layers. */ export interface WebAuthService { /** * True when the request carries a valid session cookie, or when it is a * genuine loopback request (loopback peer address *and* loopback `Host`), * which is implicitly trusted and needs no session. */ authenticate(request: IncomingMessage): boolean; } /** * @internal Test-only: forget every failure the limiter has recorded. * * The limiters are module-global (that is the point — a per-process view is * what makes the aggregate counter work), so a test that exercises them would * otherwise leak its failures into every later test in the same file. Tests * call this in `beforeEach` instead of relying on picking unused addresses. */ export declare const internals: { /** Clear both the per-client map and the aggregate counter. */ resetLoginFailures(): void; /** The aggregate penalty for a given failure count (pure, for exact checks). */ globalBackoffMs: typeof globalBackoffMs; }; /** * The global penalty for a given aggregate failure count: zero up to the free * allowance, then doubling per step, capped. * @param failures - failures recorded in the current window. * @returns the penalty in milliseconds. */ declare function globalBackoffMs(failures: number): number; /** * Install the auth policy after the web server has bound. * @param ctx - plugin context with `webServer` and `webStartup`. * @param config - resolved plugin config. */ export declare function apply(ctx: Context, _config: Config): void; export {};