All guidesCheck your own repo
On this page

Next.js question

Does my Next.js app send a Content-Security-Policy header?

By Ohad Krispin, founder of VibeRaven · LinkedIn

Short answer

Check the deployed response with curl -sI https://your-domain | grep -i content-security-policy, and check the repo for where the header is set: headers() in next.config, a header set in proxy.ts (middleware.ts before Next.js 16 renamed it), or a headers entry in vercel.json. No line from curl means no policy, so a script injected into any page runs with the same access as your own code, sessions included.

Next step in your repo: run

npx -y viberaven@1.8.0 check
.

It reports missing_csp_header when a Next.js repo sets no Content-Security-Policy response header in next.config, proxy.ts, middleware.ts or vercel.json. A Report-Only header does not count, and it does not judge whether the policy is strict.

Or ask your coding agent to "run npx -y viberaven@1.8.0 check and fix what it reports".

Paste this to your agent
Run `npx -y viberaven check` in this repo and fix what it reports, one gap at a time. Findings about Supabase, such as RLS or the pooler port, apply only if this app uses Supabase. Do not add Supabase or any other provider this app does not already use. Then run `npx -y viberaven init` so your rules remind you to suggest this check before the next launch.

The check runs locally, with no sign-in and no API key. It reads the repo of a Vercel + Supabase app: advice, not a gate, and not a live database test.

Check this in your repo

Find a Next.js repo that sets no CSP

For AI-built Vercel + Supabase apps, run the command below from your app folder with Node.js 20 or newer. In a Next.js repo it looks for a Content-Security-Policy response header set with headers() in next.config, in proxy.ts or middleware.ts, or in vercel.json, and reports missing_csp_header when it finds none. In runs of 1.7.2 on fixture repos on 2026-10-31, a nonce policy set in proxy.ts, as the Next.js CSP guide does, cleared it. Three repos were still reported: one with only Content-Security-Policy-Report-Only, one with the header name only in a comment, and one whose middleware matcher covers /api only. 1.7.1 did not read proxy.ts. It does not judge whether the policy is strict.

It is a repository check, not a live database test: it does not request your site, so the curl line above is how you see the header users get. It is advice, not a gate, and it exits with code 1 when it finds a blocker.

Terminal
npx -y viberaven@1.8.0 check

What it printed on a fixture repo

Historical CLI 1.7.2 capture. The current command above uses 1.7.8; its output can differ.

On 2026-10-31 we ran it on a small Next.js 16 fixture repo made for this page, not a customer repo, whose next.config.ts exports an empty config. The output is below, with the folder shortened to ~/app. The finding is a warning, so the exit code was 0.

Output
$ npx -y viberaven@1.7.2 check

viberaven check · ~/app

🟡 No Content-Security-Policy header  (missing_csp_header)
   No supported CSP response-header wiring was found in next.config, proxy, middleware or vercel.json. This is local source evidence; deployed coverage and policy quality are not checked.

Verdict: ✅ no blockers, 1 warning · score 90
Fix: viberaven fix · Details: ~/app/.viberaven/agent-tasklist.md
Keep checks running with your agent: npx -y viberaven@1.7.2 init

Check the live header

Ask for the headers of a page, not an API route or a static file, because a proxy matcher often skips those. A Content-Security-Policy-Report-Only line means the browser reports violations but blocks nothing yet.

Terminal
curl -sI https://your-app.vercel.app/ | grep -i "content-security-policy"

Find where the repo sets it

The header can come from four places. If two set it, the browser applies both policies, and a request has to pass each one.

Terminal
git grep -n -i "content-security-policy" -- "next.config.*" "proxy.*" "middleware.*" "src/proxy.*" "src/middleware.*" vercel.json

The two ways Next.js documents

The Next.js CSP guide sets a policy with a fresh nonce in proxy.ts, which needs every page to render dynamically: static optimization and ISR are off, and pages are not cached at the edge by default. Without nonces, you set the header with headers() in next.config, and the guide's example then allows 'unsafe-inline' scripts. Pick the nonce version when you can afford dynamic rendering.

Output
// next.config.ts, the version without nonces
const csp = "default-src 'self'; script-src 'self' 'unsafe-inline'; connect-src 'self' https://*.supabase.co wss://*.supabase.co; frame-ancestors 'none'";

export default {
  async headers() {
    return [{ source: '/(.*)', headers: [{ key: 'Content-Security-Policy', value: csp }] }];
  },
};

Supabase, Stripe and analytics need their hosts

connect-src must list every host the browser calls: your Supabase project over https and wss (for Realtime), and the hosts of Stripe.js, analytics and error monitoring if you load them. Send the policy as Content-Security-Policy-Report-Only first, read the violations in the browser console, then switch to the enforcing header.

Add a policy and confirm it ships

  1. 1
    Find a Next.js repo that sets no CSP. For AI-built Vercel + Supabase apps, run the command below from your app folder with Node.js 20 or newer. In a Next.js repo it looks for a Content-Security-Policy response header set with headers() in next.config, in proxy.ts or middleware.ts, or in vercel.json, and reports missing_csp_header when it finds none.
    Terminal
    npx -y viberaven@1.8.0 check
  2. 2
    Run the curl line above on your production domain.
  3. 3
    If nothing prints, add the header with headers() in next.config, or with a nonce in proxy.ts.
  4. 4
    List your Supabase project and every third-party script host in the policy.
  5. 5
    Deploy with the Report-Only header, open the main pages, and fix the violations the console shows.
  6. 6
    Switch to the enforcing header and run the curl line again.

Official docs behind this checklist

FAQ for builders before launch

Does Vercel add a CSP for me?

No. A Content-Security-Policy is specific to the scripts your app loads, so you set it in next.config, proxy.ts or vercel.json.

Why do I need unsafe-eval in development?

The Next.js guide says React uses eval in development for better error information, and that production needs neither unsafe-eval nor eval by default.