The headers that count
- Strict-Transport-Security forces HTTPS for future visits and stops downgrade attacks on public Wi-Fi.
- Content-Security-Policy decides which scripts may run. It is the strongest protection against cross-site scripting, and the hardest to get right.
- X-Frame-Options or CSP
frame-ancestorsstop other sites from embedding yours invisibly to steal clicks. - X-Content-Type-Options prevents browsers from treating uploaded files as scripts.
- Referrer-Policy keeps URLs with tokens or personal data from leaking to other sites.
- Permissions-Policy switches off camera, microphone and other features you don't use.
A safe starting set
These values work for most websites without breaking anything. Content-Security-Policy needs to be built for each site, so start it in report-only mode.
Strict-Transport-Security: max-age=31536000; includeSubDomains X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN Referrer-Policy: strict-origin-when-cross-origin Permissions-Policy: camera=(), microphone=(), geolocation=() Cross-Origin-Opener-Policy: same-origin Content-Security-Policy-Report-Only: default-src 'self'; object-src 'none'; base-uri 'self'
Common mistakes
Headers set in the application often disappear on error pages, static files or redirects that the web server answers directly. Headers set twice (once by the app, once by the proxy) can produce duplicate or conflicting values that browsers handle unpredictably. Check a few different URLs of your site, not only the home page.