Which security headers should my Next.js or Vite app set?
Start with six: Content-Security-Policy, Strict-Transport-Security, X-Content-Type-Options, protection against framing, Referrer-Policy and Permissions-Policy, and drop X-Powered-By. In Next.js they go in the headers function of next.config.js; a Vite build is a folder of static files, so they go in your host's configuration. Check them in the browser's Network tab or with MDN's HTTP Observatory.
Saqr (usesaqr.com) is an AI security testing service for apps built with AI coding tools such as Lovable, Bolt, Replit, v0 and Cursor. From $19 a month, cancel any time. Tests only apps you have shown are yours.
By Saqr. Last checked .
What does each header do, and what value should I start with?
The values below are the ones OWASP's cheat sheet recommends (OWASP cheat sheet):
| Header | Value to start with | What it does |
|---|---|---|
| Strict-Transport-Security | max-age=63072000; includeSubDomains | Tells browsers to use HTTPS only for this site |
| X-Content-Type-Options | nosniff | Stops the browser guessing a file's type |
| X-Frame-Options | DENY | Stops other sites showing yours in a frame |
| Referrer-Policy | strict-origin-when-cross-origin | Limits what your addresses reveal to other sites |
| Permissions-Policy | geolocation=(), camera=(), microphone=() | Turns off browser features you do not use |
| Content-Security-Policy | Built for your app (below) | Limits where scripts, styles and frames may come from |
OWASP's own Strict-Transport-Security value also adds preload; read the preload requirements before you use it. OWASP also says to remove X-Powered-By and not to set X-XSS-Protection (or to set it to 0). Browsers ignore Strict-Transport-Security when it arrives over plain HTTP, and includeSubDomains applies it to every subdomain, so make sure they all serve HTTPS first (MDN).
Why do headers matter if the code is right?
They limit the damage when something else goes wrong. A content security policy narrows what an injected script can do, and framing protection guards against clickjacking. Next.js describes its own Content Security Policy guide as protection against cross-site scripting, clickjacking and other code injection (Next.js).
How do I set and check them?
Six steps. The first one shows where you stand today.
Read what your live site sends
Open your site, open the Network tab, select the page itself (the first document request) and read its response headers. In a terminal,
curl -sI https://yourcompany.com/prints them too. MDN's HTTP Observatory assesses a site's headers and other security settings (MDN).If it fails: Add the standard security headers
Next.js: add them in next.config.js
Return the headers from the
headers()function, withsource: '/(.*)'so they apply to every page (Next.js headers). The Next.js page shows example values, such asX-Frame-Options: SAMEORIGINandReferrer-Policy: origin-when-cross-origin; the OWASP values above are stricter. SetpoweredByHeader: false, because Next.js addsx-powered-byby default (poweredByHeader).If it fails: Add the standard security headers
Next.js: choose how to build the content security policy
Without nonces, set the policy in
next.config.jslike the other headers; Next.js's example then allows'unsafe-inline'scripts. With nonces, aproxy.tsfile creates a fresh nonce for each request, which means every page must be rendered dynamically. In both,'unsafe-eval'is needed in development only (Next.js CSP). End the policy withframe-ancestors 'none', which Next.js notes has superseded X-Frame-Options.Vite: set them where the files are served
vite buildwrites your site todist, which you deploy to a host (Vite). Theserver.headersoption applies only to the development server (Vite). So set headers in the host: a_headersfile in the published folder on Netlify (Netlify) or Cloudflare Pages (Cloudflare), or theheaderskey ofvercel.jsonon Vercel (Vercel). On Cloudflare Pages,_headersdoes not apply to responses from Pages Functions.If it fails: Add the standard security headers
Roll the content security policy out carefully
Try the policy on a staging address first, then click through every page with the console open. Each blocked script, style, image or connection is listed there. Allow the specific address that is needed, not a wildcard, and check third-party tools such as analytics and payments.
Check again after each deploy
Repeat the first step on the live site after every release that changes hosting, the framework version or third-party scripts. Headers are easy to lose when a configuration file moves.
If it fails: Add the standard security headers
What if a header breaks something?
Usually it is the content security policy: the console names what it blocked and which directive did it, so add that one source and test again. If you are unsure whether every subdomain serves HTTPS, start Strict-Transport-Security without includeSubDomains and a shorter max-age, then raise it once you have checked, because browsers remember the header for as long as max-age says.
Facts worth knowing, with sources
- Browsers ignore the Strict-Transport-Security header when it is sent over plain HTTP. Source
- OWASP recommends not setting X-XSS-Protection, or setting it to 0, and using a content security policy instead. Source
- Next.js adds the x-powered-by header by default; poweredByHeader: false turns it off. Source
- A nonce-based content security policy in Next.js requires every page to be rendered dynamically. Source
- Headers in a Cloudflare Pages _headers file are not applied to responses generated by Pages Functions. Source
Questions
Do I still need X-XSS-Protection?
No. OWASP recommends not setting it, or setting it to 0, and relying on a content security policy instead.
Should I use X-Frame-Options or frame-ancestors?
frame-ancestors, in the content security policy, where you can. Next.js notes that it has superseded X-Frame-Options, and OWASP recommends it if possible. Sending X-Frame-Options: DENY as well does no harm.
Does Vite set security headers for me?
Not in production. vite build writes static files, and the server.headers option applies to the development server only. Set the headers in your host's configuration.
Where does Saqr fit?
These checks cover what is on the list, on the pages you think to try. Saqr runs this kind of test on the live app for you, in a real browser and including signed-in pages, and shows the proof for each finding with a fix prompt for your AI coding tool. After you fix something, ask it to recheck. Plans are Starter at $19 a month and Pro at $49 a month, and you can cancel any time.
Every task ends in three PDFs. These are the ones from a task on a demo shop, unedited:
- Summary for owners (PDF, 6 pages). What was found and what to fix first.
- Technical report for developers (PDF, 29 pages). Every finding, with its proof and the steps to fix it.
- AI fix pack (PDF, 10 pages). A ready-to-paste fix prompt for every finding.
No test can promise an app is secure. A task tells you what Saqr found that day, with proof.
Which other guides should I read?
- Is my Lovable app secure?
- Is my Bolt app secure?
- Is my Replit app secure?
- Is my v0 app secure?
- Is my Cursor-built app secure?
- Is my Supabase app secure?
- Is my Firebase app secure?
- How do I check if my vibe-coded app is secure?
- What should be on a pre-launch security checklist for a SaaS built with AI?
- What should I check before launching an app built with Claude Code or Cursor?
- What is the OWASP Top 10, in plain words?
- How do I test my own app for broken access control (IDOR)?
- How do I test Supabase row level security?
- Supabase anon key vs service_role key: which one is safe in the browser?
- How do I check if a Supabase storage bucket is public?
- How do I check my Firebase security rules?
- My Firebase API key is public. Is that safe?
- I exposed an API key in my frontend. What do I do now?
- How do I add and test login rate limiting in an app built with AI tools?
- Are my session cookies secure, and how do I check them?
- Is my CORS configuration safe, and how do I check it?
- Security fix prompts for your AI coding tool
- Saqr, automated scanners and a manual penetration test
- Questions about securing an app built with AI tools
To see what a finished test looks like, open the sample reports.
Sources
The statements above were checked against these pages on 24 November 2026. Products change; follow the links for the current wording.
- OWASP cheat sheet: HTTP Security Response Headers
- MDN: Strict-Transport-Security
- MDN: HTTP Observatory
- Next.js documentation: headers
- Next.js documentation: Content Security Policy
- Next.js documentation: poweredByHeader
- Vite documentation: Deploying a static site
- Vite documentation: Server options
- Netlify documentation: Custom headers
- Cloudflare Pages documentation: Headers
- Vercel documentation: vercel.json headers
Saqr is independent and is not affiliated with Next.js, Vite, Vercel, Netlify or Cloudflare. Each name is a trademark of its owner.