🔧 Unbreak My AppAll fixesError codesFix KitsSponsor

Fixes › Deploys

Missing security headers (CSP, X-Frame-Options, nosniff) on a Vercel or Netlify app

LovableBoltCursorReplitv0

Published

Weakness type: CWE-1021 (Improper Restriction of Rendered UI Layers or Frames)

The error

Mozilla HTTP Observatory, a security scanner or a client's security review flags your app: 'Content-Security-Policy (CSP) header not implemented' / 'X-Frame-Options header not set' or 'clickjacking: page can be framed' / 'X-Content-Type-Options header missing' / 'Referrer-Policy not set' / 'Server leaks version information via X-Powered-By' / you added a CSP and now the console shows 'Refused to load the script because it violates the following Content Security Policy directive' and the page is blank

Why it happens

AI builders like Lovable, Bolt, Cursor, Replit and v0 generate the app code, but security response headers are set by the server or host, so the default deploy usually ships without most of them. Browsers only apply these protections when the server sends the header. Without Content-Security-Policy, any script injected through an XSS bug can run and send data anywhere. Without X-Frame-Options or the CSP frame-ancestors directive, another site can load your login or payment page in a hidden iframe (clickjacking). Without X-Content-Type-Options: nosniff, browsers may guess file types, which OWASP says can turn non-executable content into executable content. Next.js also sends an X-Powered-By header by default, which OWASP recommends removing because it tells attackers your stack. Some protections may already be there: Vercel sends Strict-Transport-Security automatically (on *.vercel.app it is max-age=63072000; includeSubDomains; preload), so do not panic about HSTS on Vercel. The second trap is the opposite: an AI-written CSP pasted in all at once often blocks your own Supabase, Stripe or analytics requests and inline scripts, and the app goes blank.

How to fix it

  1. See what you send today. Run your live URL through Mozilla HTTP Observatory, or run curl -sI https://your-app.com and read the response headers. Note which of Content-Security-Policy, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy and Strict-Transport-Security are missing.
  2. Add the safe headers first. These rarely break anything: X-Content-Type-Options: nosniff, Referrer-Policy: strict-origin-when-cross-origin, X-Frame-Options: DENY (use SAMEORIGIN only if your own site frames itself), and Permissions-Policy: camera=(), microphone=(), geolocation=() with any feature your app really uses removed from the list. OWASP recommends these values. OWASP also says not to rely on X-XSS-Protection; set it to 0 or leave it out (some older examples still show 1; mode=block).
  3. Put them where your host reads them. On Vercel (static, Vite or any framework) add a headers entry with source "/(.*)" in vercel.json. On Netlify add a _headers file in the publish folder with a /* block, or [[headers]] for = "/*" in netlify.toml. Netlify notes these custom headers do not apply to responses from functions, edge functions or SSR pages, so set headers in that code too. In Next.js use async headers() in next.config.js and set poweredByHeader: false to drop X-Powered-By. If your builder's own hosting does not let you set headers, a proxy such as Cloudflare Response Header Transform Rules can add them.
  4. Start CSP in report-only mode. Send Content-Security-Policy-Report-Only first: the browser reports violations in the console (and to a report-to endpoint if you add one) but blocks nothing. A starting policy: default-src 'self'; script-src 'self'; connect-src 'self' https://YOUR-PROJECT.supabase.co wss://YOUR-PROJECT.supabase.co; img-src 'self' data: blob:; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'. Add each third party you really use (Stripe.js, analytics, fonts) as the console shows it.
  5. Fix the violations instead of loosening the policy. Move inline scripts into files, or use a nonce (Next.js generates a fresh nonce per request in Proxy, which means those pages render dynamically) or a hash. Avoid 'unsafe-inline' and 'unsafe-eval' in script-src, as Vercel's CSP guide advises; React and Next.js do not need 'unsafe-eval' in production. Never use * as a source.
  6. Switch to enforcing. When a few days of normal use show no unexpected violations, rename the header to Content-Security-Policy. Note that frame-ancestors and the report-only header do not work in a <meta> tag, so set them as real HTTP headers. Then rerun Observatory and curl -sI, and test login, checkout and file uploads in a private window.
  7. Remember what headers do not fix. Headers reduce the damage of XSS and clickjacking, but they do not protect your data. Missing Row Level Security, leaked keys or admin checks done only in the browser still need their own fixes (see the related pages).

Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)

Security hardening: add HTTP security response headers to my app without breaking it. My app is built with [framework] and hosted on [Vercel / Netlify / other], and it calls [Supabase project URL, Stripe, analytics and any other third-party domains]. 1) Tell me where headers must be set for this host (vercel.json headers, Netlify _headers or netlify.toml, or next.config.js headers()) and note any responses (functions, SSR) where that config does not apply. 2) Add for all paths: X-Content-Type-Options: nosniff, Referrer-Policy: strict-origin-when-cross-origin, X-Frame-Options: DENY, Permissions-Policy: camera=(), microphone=(), geolocation=() (keep only features my app does not use in the deny list). Do not add X-XSS-Protection other than 0. If this is Next.js, set poweredByHeader: false. 3) Add a Content-Security-Policy-Report-Only header (not enforcing yet) with default-src 'self', script-src 'self', object-src 'none', base-uri 'self', form-action 'self', frame-ancestors 'none', and connect-src, img-src, style-src and font-src entries for exactly the domains my app uses, including wss:// for Supabase Realtime if used. Do not use *, 'unsafe-eval' or 'unsafe-inline' in script-src; if inline scripts exist, move them to files or use nonces or hashes. 4) Do not change any application logic, auth or database code. 5) Give me a curl -sI command to verify the headers, a list of pages to click through while watching the console for CSP reports, and the exact one-line change to switch from report-only to enforcing later.

Error codes this fixes

FAQ

Why does my security scan say my vibe-coded app is missing a Content-Security-Policy?

Because CSP is an HTTP response header set by your server or host, not by the app code your AI builder wrote, and most default deploys do not send one. Add it on the host (vercel.json, Netlify _headers or next.config.js), starting with Content-Security-Policy-Report-Only so you can see what it would block before enforcing it.

Which security headers should I add first?

The low-risk ones: X-Content-Type-Options: nosniff, Referrer-Policy: strict-origin-when-cross-origin, X-Frame-Options: DENY and a Permissions-Policy that turns off camera, microphone and geolocation if you do not use them. These are OWASP's recommended values. CSP needs testing, so add it in report-only mode first.

Do I need to add Strict-Transport-Security (HSTS) on Vercel?

Usually not. Vercel's docs say *.vercel.app domains send HSTS automatically and are preloaded, and custom domains get HSTS for that subdomain. You can set your own header if you want includeSubDomains or preload on a custom domain.

I added a CSP and now my app is blank. What happened?

The policy is blocking scripts or requests your app needs, often inline scripts, Supabase, Stripe or analytics. Open the console to see each 'Refused to load' message, switch the header to Content-Security-Policy-Report-Only while you fix them, add only the exact domains you use, and move inline scripts to files or nonces instead of adding 'unsafe-inline'.

Can I set a CSP with a meta tag instead of a header?

Partly. A <meta http-equiv> CSP works for most directives, but MDN notes frame-ancestors and the Content-Security-Policy-Report-Only header are not supported in a meta element, so clickjacking protection and report-only testing need real HTTP headers.

Sources

Based on the official documentation:

Related fixes

Want the full checklist for this area? Get a Fix Kit ($29)

Get one new fix a week

Free newsletter: the newest breakages in Lovable, Bolt, Cursor, Replit and v0 apps, with paste-in fixes.

We only use your email to send the newsletter. Unsubscribe any time. See privacy.