Content / Island Framework · 25/25 Default Score · Zero-JS Islands

Astro Static & SSR Security Headers + CSP Generator

Protect Astro static builds and SSR adapters (Cloudflare, Vercel, Node) with strict `script-src 'self'`, zero inline event handlers, and 25/25 security headers.

1. Security Policy & Strict CSP Controls

OWASP + ReadyCheck Rubric
Strict-Transport-Security (HSTS · up to 5 pts)
Content-Security-Policy (CSP · up to 5 pts)
Frame, MIME, Referrer, Permissions & Cross-Origin Isolation
Permissions-Policy Disabled Features (+1 pt)
Simulated Domain / Edge Baseline (8 of 25 ReadyCheck Pts)
ReadyCheck Security Score Simulator
25 / 25 pts
READYCHECK 25/25

HTTP Headers: 17/17 pts · TLS/CAA/security.txt: 8/8 pts · COOP/CORP Hardened

HTTPS Reachable (TLS) +3/3
HTTP → HTTPS 301/308 Redirect +3/3
Strict-Transport-Security (HSTS) +5/5
Content-Security-Policy (CSP) +5/5
X-Content-Type-Options: nosniff +2/2
Clickjacking Defense (XFO / frame-ancestors) +2/2
Referrer-Policy +2/2
Permissions-Policy +1/1
DNS CAA Record +1/1
/.well-known/security.txt +1/1

2. Copy-Paste Edge & Server Configs (6 Formats)

Cloudflare _headers (_headers)
/*
  Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'none'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests
  Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
  X-Content-Type-Options: nosniff
  X-Frame-Options: DENY
  Referrer-Policy: strict-origin-when-cross-origin
  Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=(), usb=()
  Cross-Origin-Opener-Policy: same-origin
  Cross-Origin-Resource-Policy: same-origin

/assets/*
  Cache-Control: public, max-age=31536000, immutable
Live HTTP + DoH Scan ReadyCheck 100-Pt Audit

Scan your live domain headers against ReadyCheck

Verify your deployed CSP, HSTS preload, 301 HTTP→HTTPS redirect, DNS CAA, security.txt, DMARC, and AI search readiness in seconds — or grab the $49 ReadyCheck Fix Pack for tailored config bundles.

Astro — Cloudflare / Edge Middleware Header Wrapper (`src/middleware.ts`)

src-middleware.ts
import { defineMiddleware } from "astro:middleware";

export const onRequest = defineMiddleware(async (_context, next) => {
  const response = await next();
  response.headers.set("X-Content-Type-Options", "nosniff");
  response.headers.set("X-Frame-Options", "DENY");
  response.headers.set("Referrer-Policy", "strict-origin-when-cross-origin");
  response.headers.set("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload");
  return response;
});

Astro Production Rollout Caveats

  • Astro's zero-JS static output naturally pairs with `script-src 'self'` and `connect-src 'none'` unless you enable View Transitions or inline `<script is:inline>` blocks.
  • If you use Astro's `output: 'static'` on Cloudflare Pages or Netlify, drop `_headers` directly inside `public/_headers` so Astro copies it verbatim to `dist/_headers`.
  • Avoid `inlineStylesheets: 'always'` if you want to keep `style-src 'self'` without `'unsafe-inline'`.
Next Step: Run a live scan on ReadyCheck (audit.runglab.dev) to confirm headers, 301 HTTPS redirect, DNS CAA, and /.well-known/security.txt after deploy.

Other Stack & Edge Header Generators

Static Edge / Jamstack

Cloudflare Pages Security Headers

Generate a production-ready Cloudflare Pages `_headers` file with strict CSP, 25/25 ReadyCheck header score, HSTS preload, and immutable `/assets/*` caching.

Full-Stack React

Next.js Security Headers

Configure Next.js App Router security headers in `next.config.mjs` with HSTS, X-Content-Type-Options, Permissions-Policy, and strict CSP guidance for hydration scripts.

Serverless Edge

Vercel Security Headers

Generate valid `vercel.json` header arrays for Edge Network routes with HSTS preload, Permissions-Policy, Referrer-Policy, and clickjacking protection.

Reverse Proxy / VPS

Nginx Security Headers

Copy-paste hardened Nginx `server {}` block directives using `always` so 4xx/5xx error responses also emit HSTS, CSP, nosniff, and frame protection.

Static Edge / Jamstack

Netlify Security Headers

Generate a compliant Netlify `_headers` file for static sites and Edge Functions with strict CSP, HSTS preload, Referrer-Policy, and Permissions-Policy.

Single-Page App

Vite SPA Security Headers

Configure strict CSP and HTTP security headers for client-side Vite bundles hosted on Cloudflare Pages, Netlify, Vercel, or Nginx without breaking modulepreload.

← Back to Security Headers & CSP Generator Hub

Frequently Asked Questions

What ReadyCheck Security Score does this Astro baseline achieve?

With HTTPS + 301 redirect + CAA + security.txt active, this Astro preset scores 25/25 (17/17 from HTTP headers alone). Strict script-src 'self' earns the full 5/5 CSP points.

Where do I deploy the generated config in Astro?

Astro's zero-JS static output naturally pairs with `script-src 'self'` and `connect-src 'none'` unless you enable View Transitions or inline `<script is:inline>` blocks.

How do I safely allow third-party APIs or CDNs in Astro without weakening CSP?

Enter exact origins like https://api.yourdomain.com into the Custom connect-src or script-src fields above. Never add wildcard * or 'unsafe-eval', and verify your live deployment on audit.runglab.dev.