Security headers for AI-built apps

Security headers are a few lines your server sends with every page. They're free, they protect visitors in the browser, and AI builders rarely set them for you.

When your app loads, the server sends headers along with the page. Some of them tell the browser how to protect the visitor: only use HTTPS, don't run scripts from unknown places, don't let other sites frame this page. The OWASP HTTP Headers Cheat Sheet is the reference for what to send; this guide is the short version for apps built with AI tools.

The headers that matter, in order

1. HTTPS, a redirect, and Strict-Transport-Security

Every page should load over HTTPS and plain http:// should redirect to it. Then add:

Strict-Transport-Security: max-age=31536000; includeSubDomains

This tells browsers to use HTTPS for your site from now on, so a visitor on an untrusted network can't be kept on plain HTTP. Start with this and add preload only once you've read how it works: OWASP warns that a long HSTS lifetime means browsers won't load your site without valid HTTPS.

2. Content-Security-Policy

The most powerful one. It lists where scripts, styles, images and frames may come from, so an injected script doesn't run. A strict starting point:

Content-Security-Policy: default-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'

Your app probably loads things from elsewhere (fonts, analytics, Supabase, Stripe). Add those sources one by one, and test: a policy that's too strict breaks the page, which is why it's often left out. Browsers also support a report-only mode, Content-Security-Policy-Report-Only, to try a policy without enforcing it.

3. Clickjacking protection

frame-ancestors 'none' in the CSP above stops other sites from loading yours in a hidden frame. For older browsers, also send X-Frame-Options: DENY.

4. X-Content-Type-Options

X-Content-Type-Options: nosniff

Stops browsers guessing a file's type, which can turn an uploaded file into a script.

5. Referrer-Policy

Referrer-Policy: strict-origin-when-cross-origin

Keeps the full URL of your pages (which can contain ids or tokens) from being sent to other sites.

6. Remove version banners

A Server header with a version number, or X-Powered-By, tells attackers exactly what to look up. Remove them or hide the version.

What not to add

OWASP recommends not setting X-XSS-Protection (or turning it off), because the old browser feature it controls caused problems of its own.

How to add them on common hosts

Headers are set where your app is served, not in your components. A few common ways:

  • Netlify: a _headers file in your published folder (Netlify docs).
  • Vercel: a headers section in vercel.json (Vercel docs).
  • A server you run (Express, Nginx and so on): set them in the server's configuration or middleware.
  • A host that doesn't let you set headers: a proxy in front can add them, for example Cloudflare's response header rules (Cloudflare docs).

If you're not sure what your builder's hosting supports, check its documentation or ask its support. Then check the result on the address your users visit: proxies and CDNs sometimes drop headers.

A complete starting set

Put together, a reasonable starting point for most single-page apps looks like this. The example uses the format of Netlify's _headers file; other hosts take the same header names and values in their own format.

/*
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  Content-Security-Policy: default-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'
  X-Frame-Options: DENY
  X-Content-Type-Options: nosniff
  Referrer-Policy: strict-origin-when-cross-origin

Before you rely on the Content-Security-Policy line, add the outside sources your app really uses. A Supabase app, for example, usually needs its project address under connect-src, and an app that loads Stripe.js needs Stripe's addresses for scripts and frames. Open your app with the browser's developer tools → Console: a blocked request shows up there with the directive that blocked it.

How to see the headers your site sends

  • In the browser: developer tools → Network, reload, click the first request (your page) and look under Response Headers.
  • From a terminal: curl -sI https://your-app.example prints just the headers.

Check the exact address your users visit, with and without www, and after any redirect.

Check yours in seconds

Our free security headers checker runs these tests on any public address and shows the response it saw:

  • #19 HTTP redirects to HTTPS Free
  • #20 SSL certificate valid Free
  • #21 Certificate expires in more than 14 days Free
  • #22 HSTS header Free
  • #23 Content-Security-Policy present Free
  • #24 Clickjacking protection Free
  • #25 X-Content-Type-Options Free
  • #26 Referrer-Policy Free
  • #27 No mixed content Free
  • #28 Server version hidden Free

Questions

Will a Content-Security-Policy break my app?

It can, if it's stricter than what your app loads. Start from a policy that allows your own site, add the outside services you use, and test every page before you rely on it.

Do security headers matter for a small app?

Yes. They cost nothing, protect every visitor, and stop whole classes of attacks like clickjacking and injected scripts. Size doesn't change the risk to the people using it.

My headers checker says HSTS is missing but I use HTTPS. Why?

HTTPS protects a connection once it's made. HSTS tells the browser to always use HTTPS next time, so the first request can't be quietly downgraded. They work together.

Check your live app now

Paste your app's address. The free scan runs 46 tests and shows proof for everything it finds.