Response headers
What you need to know
Response headers describe HTTP behavior and can express security or caching policy. They are useful only when the actual response contains the intended values and the policy fits the content.
By the end, you can: choose a safe header policy; verify actual response.
Set a narrow header policy in next.config.ts
import type { NextConfig } from 'next';const config: NextConfig = { async headers() { return [{ source:'/catalog/:path*', headers:[ {key:'X-Content-Type-Options', value:'nosniff'}, {key:'Referrer-Policy', value:'strict-origin-when-cross-origin'} ] }]; }};export default config;Expected behavior: Catalog responses should contain both configured headers. No claim is made about unrelated routes or a complete security policy.
How it works
The async headers configuration returns source patterns and key/value header lists. Match the narrowest necessary route family. X-Content-Type-Options: nosniff asks browsers not to reinterpret certain resource types; it is not a replacement for correct Content-Type. Referrer-Policy controls what referral information is sent during later requests. A content security policy needs an explicit script/style/resource design and production tests, not a copied permissive template. Cache-Control must reflect the actual privacy and freshness requirements; a framework-managed or immutable asset may have a framework-controlled cache policy, so a custom rule does not guarantee a final header. A user-specific response should not enter a shared cache. HTTP intermediaries can also change the final response. Request header overrides in Proxy and outgoing response headers are different operations; never echo all incoming credentials as a diagnostic.
Inspect a running approved loopback server
curl -sS -D - -o /dev/null http://127.0.0.1:3000/catalogcurl -sS -D - -o /dev/null http://127.0.0.1:3000/old-booksExpected behavior: Inspect status and response headers for both requests without following redirects. These commands are staged; no server is assumed running.
Common mistake
Do not infer security from the presence of a configuration object. Do not weaken CSP, set permissive CORS or mark private content public to make an example work.
Practice and verification
Write an expected header matrix for a catalog page, redirect, missing path and private account page. Verify the actual production response and relevant browser behavior when an approved host is available.
Scope: Proposed Next.js 16.x, React 19, Node runtime. Root-mounted Pages and mixed-router fixtures with Cache Components disabled; the basePath example is separate. Framework examples are staged, not executed. Exact patched dependencies and platform contracts pending.