Your app is missing its security headers
Security headers are instructions your server sends the browser about how to treat your site: what scripts to trust, whether to force HTTPS, whether other sites can embed you. They are cheap to add and close off several common attacks at once.
Most AI-built apps ship with none of them, because nothing forces you to set them.
Which headers matter most?
You do not need every header. Start with these:
- Content-Security-Policy: limits which scripts can run, blunting cross-site scripting (XSS).
- Strict-Transport-Security (HSTS): forces browsers to use HTTPS.
- X-Frame-Options / frame-ancestors: stops other sites embedding yours in an iframe (clickjacking).
- X-Content-Type-Options: nosniff, stops content-type guessing.
Set the headers once in your framework config so every response carries them. Start strict on the ones with low risk (HSTS, nosniff, frame-ancestors) and roll out Content-Security-Policy carefully, since a too-tight policy can block your own scripts.
- Add a headers configuration to next.config.js (or your host’s config).
- Apply the headers to all routes.
- Test that your own scripts and styles still load, then tighten the CSP.
- Re-scan to confirm the headers are present.
// next.config.js
const securityHeaders = [
{ key: 'Strict-Transport-Security', value: 'max-age=63072000; includeSubDomains; preload' },
{ key: 'X-Content-Type-Options', value: 'nosniff' },
{ key: 'X-Frame-Options', value: 'DENY' },
{ key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
{ key: 'Content-Security-Policy', value: "default-src 'self'; img-src 'self' data:;" },
];
module.exports = {
async headers() {
return [{ source: '/:path*', headers: securityHeaders }];
},
};
FAQ
Will a Content-Security-Policy break my site?
It can if it is too strict, because it will block scripts and styles it does not explicitly allow. Roll it out in report-only mode first, watch for violations, then enforce it.
Do headers replace fixing the actual bugs?
No. Headers are defence in depth. They make attacks harder but do not fix an open database or an injectable query. Fix those first.