Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 1 min read

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

  1. Next.js: return the headers from headers() in next.config for every path (source: "/(.*)"). Vite and other static apps: set them in vercel.json, a _headers file on Cloudflare Pages, or your server.
  2. Start with Strict-Transport-Security: max-age=63072000; includeSubDomains, X-Frame-Options: DENY (or frame-ancestors 'none' in the policy), X-Content-Type-Options: nosniff and Referrer-Policy: strict-origin-when-cross-origin.
  3. Add a Content-Security-Policy last, listing the scripts, styles and connections your app really uses (your database, payments, analytics). Try it as Content-Security-Policy-Report-Only first, so nothing breaks while you tune it.
  4. 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.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.