Security Headers and CSP
Apply baseline HTTP security headers in Next.js config and attach a centralised Content Security Policy in the proxy pipeline.
Overview
The starter applies security headers in two layers:
- baseline headers from
next.config.ts Content-Security-Policyfrom a dedicated proxy step backed byconfig/csp.ts
This keeps common headers simple while allowing CSP rules to be managed in one place as directive arrays.
Key implementation paths:
apps/web/next.config.tsapps/web/config/csp.tsapps/web/src/proxy/csp.tsapps/web/src/proxy.ts
Baseline HTTP security headers
apps/web/next.config.ts sets headers for /(.*):
Referrer-Policy: strict-origin-when-cross-originX-Content-Type-Options: nosniffX-Frame-Options: SAMEORIGINPermissions-Policy: web-share=*, autoplay=*
The same config also sets poweredByHeader: false.
Content Security Policy (CSP)
Directive source of truth
apps/web/config/csp.ts defines each directive as a dedicated array (for example SCRIPT_SRC, IMG_SRC, CONNECT_SRC, FRAME_ANCESTORS) and serialises them into a single header string.
It also includes:
object-src 'none'base-uri 'self'form-action 'self'- optional
upgrade-insecure-requests(enabled by default)
Header attachment in proxy
apps/web/src/proxy/csp.ts generates the header via cspHeader() and sets:
Content-Security-Policy: <computed policy>
This proxy step runs in the central pipeline defined in apps/web/src/proxy.ts, after site setup and CMS redirects.
Operational notes
- Update host allowlists by editing directive arrays in
apps/web/config/csp.ts. - Keep analytics, embeds, CMS assets, and preview tooling domains aligned with your enabled integrations.
frame-ancestorsis explicitly configured, including local development and selected trusted domains.- If you tighten CSP directives, verify runtime integrations that depend on script, style, frame, media, or connect sources.
Last updated: 27 Apr 2026, 14:59:48
Password Protection
Gate the site behind a shared password at the proxy layer, with cookie-based access and optional automation bypass.
Caching and Invalidation
Use layered cache tags and webhook-driven revalidation to keep page, redirect, feed, and manifest data fast while staying fresh after CMS changes.
