import { NextResponse, type NextRequest } from "next/server"; /** * A plain `host[:port]`. The Host header is the caller's to choose, and one * carrying a `;` would end the directive it is written into and start another. */ const HOST_PATTERN = /^[a-z0-9.-]+(?::\d+)?$/i; type PolicyInput = { nonce: string; /** The host the page was requested on, which is where its room socket lives. */ host: string; /** Served over https, as every deployment is; plain http is a local run. */ secure: boolean; dev: boolean; }; /** * The page's Content-Security-Policy. * * The room key lives in the URL fragment, so a script that should not be on * the page could read it and undo the end-to-end encryption. Scripts are * therefore allowed by a per-request nonce and nothing else: no inline script * without it, and no host allowlist for one to be loaded from. * * Styles are looser. Sonner injects a `