--- name: audit-headers version: 1.2.2 description: | Audit security headers in a pracht app: `headers()` exports that weaken the defaults, static hosts that drop them, and HSTS and CSP choices. Use for "audit security headers", "check CSP", "harden headers", "set up HSTS". allowed-tools: - Bash - Read - Grep - Glob --- # Pracht Audit Headers What the framework guarantees: four default security headers are applied automatically on every framework response path that can be a document — SSR pages, API responses, 404s, and static/ISG output on the first-party adapters (`adapter-node`, `adapter-cloudflare`) as well as the Vercel headers config generated at build time: - `permissions-policy` (disables device sensors) - `referrer-policy: strict-origin-when-cross-origin` - `x-content-type-options: nosniff` - `x-frame-options: SAMEORIGIN` The helper behind this (`applyDefaultSecurityHeaders`) only sets a header **when missing** — so a route or shell `headers()` export always wins, including when it weakens a default. The framework does NOT set `strict-transport-security`, `content-security-policy`, or `cross-origin-*` headers — those need a project decision. An immutable script, stylesheet, font, or source map under `/assets/` served is never a document, so it carries only `x-content-type-options: nosniff`, without the three document-only headers, on every first-party adapter (Node and Netlify also drop `etag` / `last-modified`). HTML, SVG, JSON, images, and public files keep all four. This is not a gap — do not report it as a finding. One deliberate exception: **protocol-switch responses** (a `101` WebSocket handshake, or any response carrying a `webSocket` handle) are returned exactly as the handler produced them, with no headers applied. This is not a gap — copying the response would destroy the socket, and a handshake has no body for a sniffing or framing policy to protect. Do not report it as a finding. The audit surface is therefore: - **(a)** `dist/client` served by a custom CDN/host outside the first-party adapters — nothing applies the defaults there. - **(b)** `headers()` exports that override a default with a weaker value. - **(c)** HSTS and CSP, which genuinely need user action. Prerequisites: `pracht inspect` requires a vite config that registers the pracht plugin; `pracht inspect build` and `dist/server/headers-manifest.json` require a prior `pracht build`. Every serverful target publishes a client copy at `dist/client/_pracht/headers.json`; only Cloudflare reads it there. Pure static exports deliberately do not publish that copy. ## Step 1: Inventory header sources ```bash pracht inspect routes --json pracht inspect api --json ``` MCP: if `pracht dev-mcp` is registered, prefer its `inspect_*`, `doctor`, and `verify` tools to the CLI. Only route modules and shells have a `headers()` export — API handlers do not (there is no `headers` in the API module shape; API handlers set headers inline on the `Response` they build, and the runtime applies the defaults on top). Inventory: - `headers()` exports in route files, loader files (`loaderFile`), and shells (`shellFile`). - Hand-rolled `Response` constructions in API handlers and middleware where security-relevant headers are set inline. ## Step 2: Find weakened defaults and uncovered static hosting Defaults are framework-applied, so do not build a "which route is covered" matrix — instead: 1. For each `headers()` source from Step 1, flag any of the four default header names set to a weaker value (e.g. `x-frame-options: ALLOWALL`, an over-permissive `permissions-policy`, `referrer-policy: unsafe-url`). Because the defaults are set-when-missing, the route value wins. 2. Ask how `dist/client` is deployed. On `adapter-node`, `adapter-cloudflare`, or the generated Vercel config, static/ISG responses get the defaults. If a custom CDN or host serves `dist/client` directly, flag it (`warn`) and recommend replicating the four defaults in that host's header config. ## Step 3: HSTS Grep for `strict-transport-security`. If absent everywhere, recommend adding it (e.g. via a shell `headers()` export or the host's config): ```ts "strict-transport-security": "max-age=63072000; includeSubDomains; preload" ``` Only recommend `preload` if the user confirms they want to commit to HTTPS permanently and submit to the preload list. ## Step 4: Content-Security-Policy Start from the starter policy in , then adjust it for speculation and add observed origins: 1. Check which routes use `speculation`: read the `speculation` field from `pracht inspect routes --json` (requires a current `@pracht/cli`; on older CLIs, grep the manifest for `speculation:` instead). Those routes emit an inline `