Missing security headers in your AI-built app: what they do and how to add them

By AI App Medic · Updated · Security · Headers · Deploy

Security headers are instructions your server sends with every page, telling the browser to switch on protections that are off by default. They do not fix bugs in your code, but they make whole classes of attacks much harder. Most AI-built apps ship with none of them, which is why they show up in almost every scan.

The headers, in plain English

HeaderWhat it doesSafe starting value
Strict-Transport-SecurityAlways use HTTPS for this domain, even if someone types http://max-age=31536000 (add includeSubDomains only if every subdomain has HTTPS)
X-Content-Type-OptionsStops the browser from guessing file types (MIME sniffing)nosniff
Content-Security-Policy with frame-ancestorsControls which sites may embed you in an iframe (clickjacking)frame-ancestors 'none'
X-Frame-OptionsOlder equivalent of frame-ancestors for old browsersDENY
Referrer-PolicyLimits how much of your URL leaks to other sitesstrict-origin-when-cross-origin
Permissions-PolicyTurns off browser features you do not usecamera=(), microphone=(), geolocation=()
Content-Security-PolicyAllow-list of where scripts, styles, images and API calls may come from. Strongest protection against XSS.Build it per app (see below)

Netlify: public/_headers

/*
  Strict-Transport-Security: max-age=31536000
  X-Content-Type-Options: nosniff
  X-Frame-Options: DENY
  Referrer-Policy: strict-origin-when-cross-origin
  Permissions-Policy: camera=(), microphone=(), geolocation=()
  Content-Security-Policy-Report-Only: default-src 'self'; connect-src 'self' https://*.supabase.co wss://*.supabase.co; img-src 'self' data: https:; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'

Vercel: vercel.json

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

nginx

add_header Strict-Transport-Security "max-age=31536000" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "DENY" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;

Watch out: in nginx, an add_header inside a location block replaces all headers inherited from the server block. Repeat them, or use an include file.

Building a Content-Security-Policy without breaking the app

  1. Start with Content-Security-Policy-Report-Only. The browser reports violations in the console but blocks nothing.
  2. List what your app really loads: Supabase (https://*.supabase.co and wss://*.supabase.co for realtime), Stripe.js (https://js.stripe.com), analytics, fonts, image CDNs.
  3. Click through every page and fix violations by adding sources, not by adding *.
  4. Switch the header name to Content-Security-Policy once the console is clean.

Check the result with our free scan. It lists exactly which headers are missing on your live site.

FAQ

Are missing security headers a serious vulnerability?

Usually not on their own. They are defence-in-depth: they limit damage from other bugs such as XSS or clickjacking. They are cheap to add, and security reviewers and enterprise customers check for them.

Can a Content-Security-Policy break my app?

Yes. A strict CSP blocks scripts, styles or API calls it does not allow. Start with Content-Security-Policy-Report-Only, watch the console, then enforce.

Can I add headers on Lovable's own hosting?

Check your host's current documentation for custom header support. If it is not available, you can put a proxy such as Cloudflare in front of the domain, or deploy the built app to a host that supports headers.

Related guides