/** * Secure HTTP Headers Middleware * * A Helmet-equivalent bundle shipping OWASP-recommended defaults for: * - Content-Security-Policy (CSP) — see `./csp.ts` * - Strict-Transport-Security (HSTS) * - X-Frame-Options (legacy; superseded by CSP `frame-ancestors`) * - X-Content-Type-Options * - Referrer-Policy * - Permissions-Policy * - X-XSS-Protection (legacy; explicitly `"0"` on modern clients) * * Strategy: we implement `MiddlewarePlugin` rather than the bare * `(ctx) => Response | void` signature so we can mutate the outgoing Response * via `afterHandle`. This mirrors `cors.ts` and means we do NOT need any * framework modifications, a new "pending headers" buffer in the context, or * a custom wrapper helper that callers must remember to invoke. * * Ordering vs. session/cookies: * Unlike session middleware, which must commit BEFORE the response is * built (DX-3 + Phase 2.3), header-setting middleware can run AFTER the * response is produced — we use `afterHandle` which receives the fully- * constructed Response and returns a replacement. No ordering hazard with * cookies/session state, because we never touch `ctx.cookies`. * * CSP nonce plumbing: * When `csp.nonce === true`, we compute a fresh nonce in `beforeHandle` * and stash it on the context under the key `"csp-nonce"`. SSR handlers * that render inline `