No security headers: Content-Security-Policy, HSTS and X-Frame-Options
Without security headers, other sites can frame your app to trick clicks and injected scripts run freely. Three lines of config close whole classes of attack. What you see A security scan or a customer's revi
Without security headers, other sites can frame your app to trick clicks and injected scripts run freely. Three lines of config close whole classes of attack.
What you see
A security scan or a customer's review flags missing headers, or your app can be shown inside someone else's page.
Why it happens
Browsers only enforce these protections when the server asks for them in response headers. AI tools and starter templates rarely add them, and hosts don't add most of them for you.
How to fix it
- Next.js: return the headers from
headers()innext.configfor every path (source: "/(.*)"). Vite and other static apps: set them invercel.json, a_headersfile on Cloudflare Pages, or your server. - Start with
Strict-Transport-Security: max-age=63072000; includeSubDomains,X-Frame-Options: DENY(orframe-ancestors 'none'in the policy),X-Content-Type-Options: nosniffandReferrer-Policy: strict-origin-when-cross-origin. - Add a
Content-Security-Policylast, listing the scripts, styles and connections your app really uses (your database, payments, analytics). Try it asContent-Security-Policy-Report-Onlyfirst, so nothing breaks while you tune it. - Check the result in your browser's developer tools (Network, the page's response headers).
Or ask your AI tool to fix it
Paste this into Lovable, Bolt, v0, Replit or Cursor:
Add security headers to every response: Strict-Transport-Security, X-Frame-Options DENY, X-Content-Type-Options nosniff, Referrer-Policy strict-origin-when-cross-origin, and a Content-Security-Policy that allows only the scripts, styles, images and connections this app actually uses. Put them in the framework's headers config, not in individual pages.
The full page, with the request ready to copy, is at launchpad.axonscape.com/fix/security-headers-missing. I work on Launchpad by Axonscape, which runs a free launch check for apps built with AI tools: it finds this and the other things that break at launch, from a public GitHub repo or a .zip of the code, and keeps nothing.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.