Security headers for AI-built apps: what to add and how
Response headers are short instructions your server sends with every page. A few of them tell the browser to be stricter about what your page can do. Many new apps ship without them because nothing visibly breaks.
The four to start with
X-Content-Type-Options: nosniffstops browsers from guessing a file's type, which blocks a class of tricks where a file is treated as a script.X-Frame-Options: DENY(orSAMEORIGIN) stops other sites from putting your app inside their page, which is how clickjacking works. The modern equivalent is theframe-ancestorspart of the next header.Content-Security-Policylists where scripts, images and other resources may load from. It is the most powerful and the easiest to get wrong, so start in report-only mode.Referrer-Policy: strict-origin-when-cross-originlimits what other sites learn about where visitors came from.
Strict-Transport-Security (HTTPS only) and Permissions-Policy are also worth adding once these are in place.
How to check yours
- Open the developer tools (F12) and the Network tab.
- Reload the page and click the first request, usually your page's address.
- Read the Response Headers. Look for the four names above.
Netlify and Cloudflare Pages
Create a file named _headers in your publish folder:
_headers
/*
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
Referrer-Policy: strict-origin-when-cross-origin
Content-Security-Policy-Report-Only: default-src 'self'; frame-ancestors 'none'
Vercel
vercel.json
{
"headers": [
{
"source": "/(.*)",
"headers": [
{ "key": "X-Content-Type-Options", "value": "nosniff" },
{ "key": "X-Frame-Options", "value": "DENY" },
{ "key": "Referrer-Policy", "value": "strict-origin-when-cross-origin" }
]
}
]
}
Next.js and Express
next.config.js
module.exports = {
async headers() {
return [{
source: "/(.*)",
headers: [
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "X-Frame-Options", value: "DENY" },
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
],
}];
},
};Express (with the helmet package)
import helmet from "helmet";
app.use(helmet());
Take the Content Security Policy slowly
A strict policy can block your own scripts, fonts or analytics. Start with Content-Security-Policy-Report-Only, open your app, watch the browser console for what would have been blocked, adjust, and only then switch to the enforcing header. Test sign-in and payment pages especially.
Common questions
Do security headers make my app secure?
No. They remove some common ways of attacking a page, and they cost almost nothing to add. They are one layer among many.
Want this checked on your app?
The free quick look and the complete check both read your response headers and cookie settings, and report which of the basic ones are missing.
We email you once when a spot opens. No spam, and you can ask us to remove you any time at support@appinvestigators.com.
Related guides
- Vibe coding security checklist: what to check before you launch
- Check for exposed .env files, source maps and open folders
- Stop showing stack traces and error details to visitors
Last updated 2026-11-24. This guide describes common problems and fixes. It is not a guarantee that any app is secure or free of bugs.