A security scan, a client's IT check or a pen-test report came back with "missing security headers": Content-Security-Policy, Strict-Transport-Security and a few more. Your app works fine, so is this real? Yes, but it is a small, fixable job, and one header needs care. Facts below come from MDN, hstspreload.org and the Netlify, Vercel, Cloudflare and Stripe docs, checked in November 2026.
Short answer: add four low-risk headers first: Strict-Transport-Security (if your host doesn't send it already, and without preload), X-Content-Type-Options, Referrer-Policy and Permissions-Policy. Block framing with X-Frame-Options or CSP frame-ancestors. Then roll out Content-Security-Policy slowly, in report-only mode first, because it is the one that can break your app.
What each header does
A header is a line your host sends with every page. The browser reads it and applies rules. Here is each one, in plain English, with a safe starting value.
- Strict-Transport-Security (HSTS). MDN says it "informs browsers that the host should only be accessed using HTTPS". So later visits over plain HTTP get upgraded. Your host may send it already: Vercel's encryption docs show
max-age=63072000as "The default Strict-Transport-Security header for custom domains". Runcurl -Ifirst (see below). If it is there, leave it. If not, start withmax-age=300and raise it later. - X-Content-Type-Options. With
nosniff, MDN says "the browser uses the supplied Content-Type as-is instead of examining the content to infer the type". It stops a file from being run as something it is not. Value:nosniff. - X-Frame-Options. MDN says sites use it "to avoid clickjacking attacks", where another site hides your page in a frame and tricks people into clicking. Value:
DENY, unless you need your page framed. - Referrer-Policy. MDN says it "controls how much referrer information" goes out with requests. It limits how much of your URLs other sites see. MDN says
strict-origin-when-cross-origin"is the default policy if no policy is specified", so setting it just makes it explicit. - Permissions-Policy. MDN says it lets you "allow and deny the use of browser features in a document". It stops a page or a framed widget from asking for your visitor's camera or location. Value:
camera=(), microphone=(), geolocation=(), if your app uses none of them. - Content-Security-Policy (CSP). MDN says it tells the browser to "place restrictions on the things that the code comprising the site is allowed to do". It is your best defence if someone manages to inject a script into your page. It needs its own section below.
Clickjacking has two fixes. MDN's X-Frame-Options page says: "For more comprehensive options than offered by this header, see the frame-ancestors directive in a Content-Security-Policy header." MDN's CSP guide says of frame-ancestors: "This directive is a more flexible replacement for the X-Frame-Options header." Sending both is fine.
The pages for the others: Strict-Transport-Security, X-Content-Type-Options, Referrer-Policy and Permissions-Policy.
HSTS: go slowly with preload
HSTS has three parts. max-age is, per MDN, "the time, in seconds, that the browser should remember that a host is only to be accessed using HTTPS". includeSubDomains applies the rule to all subdomains too. preload asks to be put on a list built into browsers.
Be careful with the last two. If one subdomain cannot do HTTPS, includeSubDomains will break it. For preload, hstspreload.org is blunt: "Be aware that inclusion in the preload list cannot easily be undone." It also says removal "tends to be slow and painful" and tells you to "do not include the preload directive by default".
My advice: if you add HSTS yourself, start with a short max-age, confirm the site works on HTTPS everywhere, then raise it. Don't replace a longer value your host already sends with a shorter one. Skip preload unless you have a real reason.
CSP without breaking the app
CSP is the one to roll out in steps.
- Start in report-only mode. MDN: "To ease deployment, CSP can be deployed in report-only mode." Use the
Content-Security-Policy-Report-Onlyheader. The browser logs what it would have blocked and blocks nothing. - Read the browser console. Open your app, log in, pay with a test card, upload a file. Each warning names the blocked address.
- Allow what your app really needs, then switch the header name to
Content-Security-Policy.
Here is what usually breaks:
- Inline scripts. MDN says that with
default-srcorscript-src, inline JavaScript will not run unless you take extra steps. It warns: "Developers should avoid 'unsafe-inline'". Move scripts into files, or use a nonce or hash. On a nonce, MDN says "the nonce must be different for every HTTP response". That is hard on a static site, so files are easier. - Stripe. Stripe's integration security guide lists "the full set of directives for Stripe products". For Stripe.js it lists
connect-srchttps://api.stripe.com,script-srchttps://js.stripe.comandhttps://*.js.stripe.com, andframe-srchttps://js.stripe.com,https://*.js.stripe.comandhttps://hooks.stripe.com. It also says that for payment methods with redirects, such as 3D Secure, you should "include https://hooks.stripe.com as a frame-src directive". Checkout and Link have their own lists on that page. - Your database or login API. Calls from the browser to Supabase, Firebase or your own API are controlled by
connect-src. Add your API host there. Check your provider's docs for any extra hosts, such as websocket addresses. - Analytics, fonts and images from other hosts. Each one needs its host in the right directive (
script-src,font-src,img-src). The console warning tells you which.
A <meta> tag is not the same as a header. MDN says a meta CSP is useful for some cases "such as a client-side-rendered single page app", but "this option does not support all CSP features". It also says a report-only policy "cannot be delivered in a <meta> element". So use real headers for the rollout.
A starting policy to put in report-only mode, for an app that uses Stripe.js and one API host. Change the API host:
default-src 'self'; script-src 'self' https://js.stripe.com https://*.js.stripe.com; connect-src 'self' https://api.stripe.com https://api.example.com; frame-src https://js.stripe.com https://*.js.stripe.com https://hooks.stripe.com; img-src 'self' data:; frame-ancestors 'none'
This is my example, not an official template. Your app will need changes.
How to add them on your host
Netlify. The Netlify headers docs give two ways: "Save a plain text file called _headers to the publish directory" of your site, or "Add one or more headers tables to your Netlify configuration file". A _headers file looks like this:
/* X-Content-Type-Options: nosniff Permissions-Policy: camera=() X-Frame-Options: DENY
In a Vite or similar project, put the file in public/ so it is copied to the publish folder. Check that after a build. The same docs show the netlify.toml form as [[headers]], with for and a [headers.values] table.
Vercel. Vercel's vercel.json docs have a headers list. Each entry has a source path and a headers list of key and value pairs:
{
"headers": [{
"source": "/(.*)",
"headers": [{
"key": "X-Frame-Options",
"value": "DENY"
}]
}]
}
Cloudflare Pages. Cloudflare's docs say to create "a plain text file called _headers without a file extension, in the static asset directory of your project".
Lovable, Bolt and other builders. I found no official page that says how to set custom response headers there, so I won't guess. Check whether your host lets you set response headers. If it does not, put the site behind a host that does. See moving a Lovable or Bolt app to your own GitHub and hosting.
Check your result
- MDN HTTP Observatory. Per MDN, it "performs an in-depth assessment of a site's HTTP headers and other key security configurations". Open the Observatory, enter your address and fix what it flags.
- curl. Run
curl -I https://your-app.exampleand look for your headers in the reply. - Browser Network tab. Click the page request and read the response headers. The Console shows CSP warnings.
- Re-test after every change: log in, pay with a test card, upload a file.
What headers do not fix
Headers add a safety net in the browser. They do not replace server-side checks. A perfect score will not stop a stranger reading your database if the rules are open. Check the five database checks, whether an API key is exposed and admin pages and roles. A "blocked by CORS policy" error is a different thing from these headers. It is covered in the CORS fix.
Prompts for Lovable, Bolt and Cursor
- "My app is hosted on Netlify. If my host doesn't already send Strict-Transport-Security, add it with a max-age of 300 seconds and no preload. Add 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. Put them in the right file for my host and tell me where it is."
- "Build a Content-Security-Policy-Report-Only header from the hosts my app actually loads: list every script, style, font, image and API address in the code. Do not enforce it yet, and do not use 'unsafe-inline'."
- "Move every inline script and inline event handler into its own file, so a CSP does not need 'unsafe-inline'. Don't change how the app looks or works."
Ask for one change at a time, and test login and payments after each.
Checklist
- Scan your site with the MDN HTTP Observatory and note what is missing.
- Add X-Content-Type-Options, Referrer-Policy, Permissions-Policy and a framing rule.
- Check whether your host already sends HSTS. If not, add it with a short max-age. No preload.
- Add CSP as Report-Only. Use the app fully and read the console.
- Add the missing hosts, such as Stripe and your API, then enforce.
- Re-run the scan and
curl -I. Test login, payments and uploads. - Do the other security checks too. Headers are only one layer.
Want this fixed for you?
I finish and fix apps built with Lovable, Bolt, Cursor or Replit, including setting security headers without breaking payments or login. Or send me the details and I'll reply within 24 hours.