Missing security headers: which 5 your app needs and how to add them

Checked on

Add five headers to your HTML pages: Content-Security-Policy (limits where scripts and files can load from), Strict-Transport-Security (tells browsers to always use https for your site), X-Frame-Options or CSP frame-ancestors (blocks other sites from embedding yours), X-Content-Type-Options: nosniff (stops browsers from guessing file types) and Referrer-Policy (controls how much of your page address other sites see). Set them at your host (Cloudflare, Vercel or Netlify), not in a meta tag. You don’t need a perfect score.

The 5 headers that matter

Most generated apps send only the headers their host adds by default. You do not need a perfect score. You do want five of them on the HTML response: Content-Security-Policy (limits where scripts and files can load from), Strict-Transport-Security (tells browsers to always use https for your site), X-Frame-Options or CSP frame-ancestors (blocks other sites from embedding yours), X-Content-Type-Options: nosniff (stops browsers from guessing file types), and Referrer-Policy (controls how much of your page address other sites see). Permissions-Policy (turns off browser features your site does not use) is worth adding once the first five exist.

X-XSS-Protection is obsolete. A missing favicon is not a vulnerability. A missing CSP isn’t a problem on its own, but it is the header that limits damage when a secret or a third-party script ends up in the page.

What each one is for

HSTS tells the browser to keep using HTTPS, so a later visit cannot be downgraded. Set it only after the site really is HTTPS everywhere, including subdomains if you include includeSubDomains.

X-Frame-Options: DENY, or CSP frame-ancestors 'none', stops another site from embedding your login page and clicking through it. nosniff stops a browser from treating a user upload as HTML. Referrer-Policy: strict-origin-when-cross-origin keeps full paths from leaking when someone clicks out to Stripe or a docs site.

Where to set them

On Cloudflare, put the headers in a _headers file or the Workers assets config. On Vercel, vercel.json or next.config. On Netlify, netlify.toml. A host-level header is better than a meta tag, because meta tags cannot set HSTS or frame-ancestors reliably.

A Cursor prompt: “Add security headers to the HTML responses: Content-Security-Policy with a default-src that matches the scripts this app actually loads, Strict-Transport-Security, X-Content-Type-Options nosniff, Referrer-Policy strict-origin-when-cross-origin, and X-Frame-Options DENY. Do not break the Stripe.js or Supabase domains the app already calls.” Start the CSP in report-only if you are unsure which domains the app loads.

The free scan tells you which of these your homepage is missing.

How to find out sooner next time

Run the free scan after you change hosts or deploy settings. It reads the headers on your homepage and lists the missing ones. For a monitored app, the same scan runs again with every scheduled check.

Let Heedza check this for you. Heedza’s security checks tells you if a secret key or a private file can be seen by the public. It checks again every time it checks your pages. It never logs in or fills in forms, so it can’t see errors that only show after that.

Made with Lovable, Bolt, Replit, Cursor or v0? Free for 1 site: start free or see prices.

More questions

Do I need every security header a scanner lists?

No. Start with the five above. X-XSS-Protection is obsolete, and a missing favicon is not a security problem.

Can I add security headers with a meta tag?

Only some of them. HSTS and frame-ancestors don’t work reliably in a meta tag, so set the headers at your host.

Will a Content-Security-Policy break my app?

It can, if it blocks a script your app needs, such as Stripe.js or Supabase. Start with Content-Security-Policy-Report-Only to see what would be blocked, then switch it on.