Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 1 min read

No Content-Security-Policy on your AI-built app: what to set and how to roll it out safely (proofforge.live)

A Content-Security-Policy (CSP) header tells the browser which scripts, styles and connections your page may load. If an attacker manages to inject a script into your page, a good CSP can stop it from running or from sen

A Content-Security-Policy (CSP) header tells the browser which scripts, styles and connections your page may load. If an attacker manages to inject a script into your page, a good CSP can stop it from running or from sending data out. AI-generated apps almost never set one.

How to check your own site

  1. Run curl -sI https://yourapp.com | grep -i content-security-policy. No output means no CSP.
  2. Or open DevTools, Network, click the document request and read Response Headers.
  3. If you have one, look for 'unsafe-inline' and 'unsafe-eval' in script-src, and for * wildcards. They weaken the policy a lot.

A sensible starting point

Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self' https://YOUR_API_HOST; frame-ancestors 'none'; base-uri 'self'; form-action 'self'

Adjust connect-src for your API and analytics hosts, and script-src for any third-party scripts you really use (payments, analytics).

Roll it out safely

  1. Start with Content-Security-Policy-Report-Only so nothing breaks while you see what would be blocked.
  2. Fix the violations the console reports. Move inline scripts to files or use nonces.
  3. Switch to the enforcing header once the console is quiet.

On Next.js, set headers in next.config.js or middleware. On Vercel or Netlify, use vercel.json or _headers. On nginx, add_header.

CSP is a second line of defence. It does not replace fixing the XSS bug itself.

Check your own app from the outside, free. Run the free ProofForge scan on your live URL. No account needed for the first scan. It looks at your public site the way a stranger would and says pass, fail or inconclusive, so you know what is confirmed and what it could not see. One-time reports start at $9: see pricing. Building with an AI agent? There is an MCP server so it can check before it deploys.

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

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