Scanora

Guides / General

Security headers on Vercel, Netlify and Cloudflare

Security headers block whole classes of attacks for free. Which headers to add, what they do, and copy-paste config for Vercel, Netlify and Cloudflare Pages.

Updated 2026-11-18

Security headers are instructions your server sends with every page, telling the browser how to protect your visitors. They take minutes to add and stop common attacks like clickjacking, protocol downgrades and many script injections. Most AI-built sites ship without them.

The headers to add

  • Strict-Transport-Security (HSTS): always use HTTPS for this site, even if someone types http://. Example: max-age=31536000; includeSubDomains
  • X-Content-Type-Options: nosniff stops browsers guessing file types, which can turn an upload into a script.
  • Referrer-Policy: strict-origin-when-cross-origin avoids leaking full URLs (which may contain tokens) to other sites.
  • X-Frame-Options: SAMEORIGIN stops other sites showing yours in a hidden frame (clickjacking). The modern equivalent is the CSP frame-ancestors rule.
  • Permissions-Policy: turn off browser features you don't use, for example camera=(), microphone=(), geolocation=().
  • Content-Security-Policy (CSP): lists where scripts, styles and images may load from. It's the strongest protection against injected scripts, and needs tuning for your app.

Vercel

Add a vercel.json file in your project root:

{
  "headers": [
    {
      "source": "/(.*)",
      "headers": [
        { "key": "Strict-Transport-Security", "value": "max-age=31536000; includeSubDomains" },
        { "key": "X-Content-Type-Options", "value": "nosniff" },
        { "key": "Referrer-Policy", "value": "strict-origin-when-cross-origin" },
        { "key": "X-Frame-Options", "value": "SAMEORIGIN" },
        { "key": "Permissions-Policy", "value": "camera=(), microphone=(), geolocation=()" }
      ]
    }
  ]
}

For Next.js you can also use headers() in next.config.js. See our v0 and Vercel checklist.

Netlify

Create a file called _headers in your publish folder (often public/ for Vite apps, so it's copied into the build):

/*
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  X-Content-Type-Options: nosniff
  Referrer-Policy: strict-origin-when-cross-origin
  X-Frame-Options: SAMEORIGIN
  Permissions-Policy: camera=(), microphone=(), geolocation=()

Or use [[headers]] blocks in netlify.toml.

Cloudflare Pages

Cloudflare Pages also reads a _headers file from your build output, with the same format as Netlify's above. For sites proxied through Cloudflare but hosted elsewhere, you can add headers with Transform Rules (Response Header Modification) in the dashboard.

Adding a Content-Security-Policy safely

A strict CSP can break your site if it blocks something you need, so roll it out in two steps:

  1. Start with Content-Security-Policy-Report-Only and a policy like default-src 'self', plus the domains your app uses (your API, Supabase, Stripe, analytics, fonts).
  2. Open your site, check the browser console for blocked items, adjust, then switch the header name to Content-Security-Policy.
Content-Security-Policy: default-src 'self'; script-src 'self' https://js.stripe.com; connect-src 'self' https://YOUR-PROJECT.supabase.co; img-src 'self' data: https:; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src https://fonts.gstatic.com; frame-ancestors 'self'

Check your headers

After deploying, check which headers your site actually sends. Scanora's free scan checks your security headers, explains each missing one, and gives the exact line to add.

Check your site in one minute

Scanora runs these checks for you: leaked keys, open files, headers, SSL, speed and AI-search readiness. Free, no signup.

Scan my site free

More guides