/** * Security response headers middleware. * * Sets a baseline set of "no-brainer" security headers on every framework HTTP * response. These headers are layered defenses: each one mitigates a specific * class of attack, and together they harden the surface against MIME-sniffing, * referrer leakage, mixed-content downgrades, and cross-origin window/embed * access. * * The headers we emit: * * - `Strict-Transport-Security` — forces HTTPS for the browser's lifetime * of the cached value, preventing SSL-strip MITM. Only emitted when the * request scheme is `https` (we don't want to break local-dev HTTP, and * emitting HSTS over HTTP is a no-op per the spec but causes confusion). * - `X-Content-Type-Options: nosniff` — disables browser MIME sniffing so * a tool /render route serving user-authored HTML can't be misinterpreted * as some other content type by a clever Accept header. * - `Referrer-Policy: strict-origin-when-cross-origin` — strips path/query * from outbound Referer headers when the request crosses origin, so a * public-share viewer's outbound link clicks never leak the share token. * - `Permissions-Policy: camera=*, microphone=(self), geolocation=(), * screen-wake-lock=()` — allows microphone access for composer dictation * and camera access for media-capture UI (the Clips recorder, and the * Clips browser extension's camera bubble, which is injected as a * cross-origin iframe and is therefore blocked outright by `camera=()`). * Location and wake-lock stay disabled. The browser still gates actual * camera/mic use behind a per-origin permission prompt, so `camera=*` only * removes the policy-level block, not the user consent. * - `Cross-Origin-Opener-Policy: same-origin` — isolates window.opener so * a popup-window opener reference can't read or modify our document. * - `Cross-Origin-Embedder-Policy: require-corp` — emitted only for * validated MCP embed-session page loads and browser iframe navigations. * COEP hosts such as Claude's MCP Apps proxy require framed cross-origin * documents to opt in explicitly. * - `Cross-Origin-Resource-Policy: same-site` — prevents other origins from * embedding our endpoints as `` / `