/** * Shared auth check for every /dashboard* page (dashboard.ts + the * dashboard-*-html.ts siblings). Previously each file duplicated its own * bearerOk/cookieOk check "by design" (independent reviewability); adding a * second auth mode (dev no-auth, see below) to N hand-copied checks would * have let them drift, so this is now the one place that decides. * * Behavior: * 1. `auth.devNoAuth` active (config true AND loopback bind — computed * once in app.ts and threaded down to every dashboard route factory) * AND the request's Host header resolves to loopback * (`isLoopbackHostHeader`) => access granted, no token/cookie required * (subject to the Origin check below). * 2. `devNoAuth` active but Host does NOT resolve to loopback => 403. This * is the same DNS-rebinding defense app.ts's preHandler applies to API * routes (see network.ts's isLoopbackHostHeader doc comment) — without * it, a page a rebinding attack served under an attacker-controlled * hostname could read memory titles/metrics off the dashboard. * 3. `devNoAuth` active, Host is loopback, but an `Origin` header is * present and does NOT resolve to loopback => 403. A `
` on a malicious page is a CORS "simple request" — no * preflight — and on a form POST the Host header is always the * TARGET (this daemon, always loopback), never the page that fired * it, so check #1/#2 above cannot see that the request actually * originated from an attacker's page rather than the dashboard's own * forms. `Origin` is the one header a form POST carries that reflects * the calling page. With `devNoAuth` off this hole is already closed * by `SameSite=Strict` on the session cookie (a cross-site form POST * simply doesn't attach it), so this check only needs to run in the * devNoAuth branch. No `Origin` header at all (curl, scripts, * same-origin navigations) passes through unchanged. * 4. `devNoAuth` inactive => unchanged pre-existing behavior: Bearer header * or the HttpOnly `astramem_dash` cookie (bootstrapped once via * dashboard.ts's `?token=` redirect) must match. */ import type { FastifyRequest } from 'fastify'; export declare const DASHBOARD_COOKIE_NAME = "astramem_dash"; export declare function readDashboardCookie(req: FastifyRequest, name?: string): string | undefined; export type DashboardAuthResult = { allowed: true; } | { allowed: false; status: 401 | 403; body: string; }; /** * Full auth decision for a /dashboard* request. `devNoAuthActive` must be * the same boot-computed condition app.ts derives (config.auth.devNoAuth * === true AND the daemon is bound to loopback) — callers must not * recompute it independently. */ export declare function checkDashboardAuth(req: FastifyRequest, token: string, devNoAuthActive: boolean): DashboardAuthResult;