How to add security headers to a site on Vercel
Last reviewed October 29, 2026 against the providers' current documentation.
The short version
Add a headers block to vercel.json at the root of your project (for Next.js, use headers() in next.config.js), push, and check the response headers of the new deployment. You don't need to add HSTS yourself: Vercel already sends it. Start the Content-Security-Policy in report-only mode, as Vercel's docs recommend, and switch it to enforcing once the browser console shows no violations.
Why it matters
Security headers are instructions your server sends with every page. Content-Security-Policy tells the browser which scripts may run, so an injected script is blocked. X-Frame-Options (or CSP frame-ancestors) stops other sites from loading your app in a hidden frame to trick users into clicks. X-Content-Type-Options: nosniff stops the browser from guessing file types. Referrer-Policy limits how much of your URLs leak to other sites. Vercel handles the transport part for you: its docs say every deployment is served over HTTPS, plain HTTP is redirected with a 308, and Strict-Transport-Security: max-age=63072000 is sent on custom domains (with includeSubDomains; preload on *.vercel.app). The rest isn't added for you.
Fix it, in this order
See what your site sends now
Run our free headers check on your live address, or open your site, press F12, go to the Network tab, reload and click the first request to read its Response Headers. On Vercel you'll normally already seestrict-transport-security; the ones usually missing arecontent-security-policy,x-frame-options,x-content-type-optionsandreferrer-policy.Vite, React, Astro or a static site: use vercel.json
Create (or open)vercel.jsonin the project root and add aheadersentry whosesourceis/(.*), which matches every path:
Each entry has a{ "$schema": "https://openapi.vercel.sh/vercel.json", "headers": [ { "source": "/(.*)", "headers": [ { "key": "Content-Security-Policy-Report-Only", "value": "default-src 'self'; script-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'self'" }, { "key": "X-Frame-Options", "value": "SAMEORIGIN" }, { "key": "X-Content-Type-Options", "value": "nosniff" }, { "key": "Referrer-Policy", "value": "strict-origin-when-cross-origin" }, { "key": "Permissions-Policy", "value": "camera=(), microphone=(), geolocation=()" } ] } ] }sourcepattern and a list ofkey/valuepairs; Vercel's docs also allowhasandmissingconditions if a header should only apply to some requests. The$schemaline is optional and gives your editor autocomplete.Next.js (and v0 apps): use next.config.js
Next.js documents its ownheaders()option, which returns the samesource+headersshape:
Theconst securityHeaders = [ { key: 'Content-Security-Policy-Report-Only', value: "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' blob: data:; object-src 'none'; base-uri 'self'; frame-ancestors 'self'" }, { key: 'X-Frame-Options', value: 'SAMEORIGIN' }, { key: 'X-Content-Type-Options', value: 'nosniff' }, { key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' }, { key: 'Permissions-Policy', value: 'camera=(), microphone=(), geolocation=()' }, ] module.exports = { async headers() { return [{ source: '/(.*)', headers: securityHeaders }] }, }'unsafe-inline'entries follow Next.js's own "without nonces" CSP example, because Next.js adds inline scripts to every page. To drop them you need nonces (generated per request inproxy.js, which makes every page dynamically rendered) or the experimental Subresource Integrity option; see the Next.js CSP guide linked below. If your project usesoutput: 'export', Next.js doesn't supportheaders(), so put the headers invercel.jsoninstead.Deploy and check the new deployment
Push the change (or runvercel --prod). Headers apply to the new deployment, so open its address and look at the response headers again, or rerun the headers check. If a header is missing, check that the file is at the project root (the folder Vercel builds from) and that thesourcepattern matches the path you tested.Watch the CSP reports, then enforce it
WithContent-Security-Policy-Report-Only, nothing is blocked; the browser console lists every script, style, image or connection the policy would have blocked. Click through your app (log in, pay, upload) and add each legitimate domain to the matching directive, for example your analytics inscript-srcand your Supabase or API address inconnect-src. When the console is clean, rename the header toContent-Security-Policyand deploy again. Until then,X-Frame-Optionsis what protects you against framing, because a report-onlyframe-ancestorsdoesn't block anything.Optional: tighten HSTS
Vercel's default on custom domains covers that one hostname only. If every subdomain of your domain works over HTTPS, you can send your ownStrict-Transport-Securityheader withmax-age=63072000; includeSubDomains; preload(Vercel's docs say you can override the default with a custom header) and then submit the domain at hstspreload.org. Don't do this if any subdomain still needs plain HTTP: browsers will refuse it for up to two years.
Or ask your AI tool to do it
Paste this into Lovable, Bolt, Cursor, Claude Code or whichever tool built your app. Review what it changes before you deploy.
My site is deployed on Vercel. Add security headers for every path. If this is a Next.js project (and not using output: 'export'), add an async headers() function to next.config.js; otherwise add a headers array to vercel.json in the project root with source "/(.*)". Add: Content-Security-Policy-Report-Only (start from default-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'self', and add every external domain the app really loads scripts, styles, fonts, images and API calls from), X-Frame-Options: SAMEORIGIN, X-Content-Type-Options: nosniff, Referrer-Policy: strict-origin-when-cross-origin and Permissions-Policy: camera=(), microphone=(), geolocation=(). Don't add Strict-Transport-Security, Vercel already sends it. List the external domains you added and why, so I can review the CSP before switching it from report-only to enforcing.
How this happens
Nothing breaks without them, so nobody adds them. Vercel's defaults (HTTPS, the redirect, HSTS) make a new deployment look finished, and AI builders like v0, Lovable or Bolt generate the app, not the hosting config. The headers only show up as a problem when someone runs a scanner or a customer's security review asks for them.
Check that it's really fixed
After you deploy, run the free check. It reads your live site the way an attacker would and tells you if any secret key is still visible.
Topic check: Security headers check
Find the other leaks before someone else does
The free check reads your home page and its scripts. The website security report goes through up to 30 pages and 40 JavaScript files, plus .env and .git files, security headers, cookies and CORS, domain and email records, and libraries with known vulnerabilities. Every finding comes with the fix for your host and a prompt for your AI tool.
$19 once, including 20 runs over 30 days so you can fix things and check again.

Questions
Does Vercel add security headers by default?
Only the HTTPS ones. Vercel's docs say every deployment is served over HTTPS, HTTP requests are redirected with a 308 that can't be disabled, and HSTS is sent automatically (max-age=63072000 on custom domains, plus includeSubDomains; preload on *.vercel.app). Content-Security-Policy, X-Frame-Options, X-Content-Type-Options and Referrer-Policy are yours to add.
vercel.json or next.config.js?
For Next.js, use headers() in next.config.js: it's Next.js's documented way and Vercel's own Next.js conformance rule points to it. For other frameworks and static sites, use vercel.json. For a Next.js static export (output: 'export'), headers() isn't supported, so use vercel.json.
Will a Content Security Policy break my site?
An enforcing one can, if it leaves out a domain your app needs. That's why you start with Content-Security-Policy-Report-Only, which Vercel's docs recommend: it blocks nothing and shows violations in the browser console. Switch to Content-Security-Policy once those are gone.
Do I still need X-Frame-Options if I set frame-ancestors?
Next.js's docs call X-Frame-Options superseded by CSP's frame-ancestors. While your CSP is report-only, though, frame-ancestors doesn't block framing, so keep X-Frame-Options until the CSP is enforced. Sending both is fine as long as they agree.
Why does your free check still say "No Content Security Policy"?
The free check only counts an enforcing Content-Security-Policy header, so a report-only one still shows up there until you switch it on. The $19 report grades the policy itself (report-only, 'unsafe-inline', 'unsafe-eval', wildcards) and drafts a starting CSP from the domains your pages actually load, with the config for the host it detects, including Vercel.
Do headers fix leaked keys or open databases?
No. Headers protect visitors' browsers. A secret key in your JavaScript or a table without access rules is a separate problem; the free check looks for keys and exposed files at the same time.
Sources
- Vercel: Static configuration with vercel.json (headers)
- Vercel: Encryption and TLS (HTTPS redirect, default HSTS)
- Vercel: Content Security Policy (start report-only)
- Vercel Conformance: NEXTJS_MISSING_SECURITY_HEADERS
- Next.js: headers in next.config.js (security header options)
- Next.js: How to set a Content Security Policy
- Next.js: Static exports (unsupported features)
- MDN: Content-Security-Policy-Report-Only