web-security-headers

Configure hash-based CSP and HTTP security headers for Astro sites on Cloudflare Workers.

Updated Jun 17, 2026
One-click install
npx skills add https://github.com/ccediland/web-stack-skills --skill web-security-headers-ccediland
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: web-security-headers
Source: https://github.com/ccediland/web-stack-skills/tree/main/plugin/skills/web-security-headers
Command: npx skills add https://github.com/ccediland/web-stack-skills --skill web-security-headers-ccediland

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up a Content Security Policy and security headers on an Astro site deployed to Cloudflare Workers Static Assets is confusing: the adapter cannot emit static headers, the CSP meta element silently drops directives like frame-ancestors, and misconfigured COEP or HSTS preload can break the site permanently. This Skill encodes the correct layer split and the gotchas so headers land in the right place the first time. ## Core Features & Use Cases - Layered header architecture: Astro's native security.csp hashes scripts and styles per page (meta element on static pages, response header on SSR), while public/_headers carries HSTS, X-Frame-Options, Referrer-Policy, Permissions-Policy, COOP, CORP, and the frame-ancestors directive. - SSR and middleware coverage: Set headers for server-rendered routes in src/middleware.ts, since _headers never touches Worker responses, with an optional nonce path as a last resort. - SRI and verification: Add Subresource Integrity for cross-origin resources via a build-time hash script, then verify deployed headers with curl, scanners, and a CSP evaluator. - Use Case: You are hardening a static marketing site on Cloudflare and need clickjacking protection, a strict CSP without unsafe-inline, and HSTS — without breaking WebGL textures or Rive embeds through an overly aggressive COEP. ## Quick Start Set up a hash-based CSP and the full security header set for my Astro site on Cloudflare Workers, including the _headers file and verification steps.

Frequently Asked Questions about web-security-headers

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a Content Security Policy to an Astro site?▼

Enable Astro's native security.csp config, which hashes bundled scripts and styles per page automatically. Set non-script directives like default-src and object-src in the directives array, and configure script-src and style-src through scriptDirective and styleDirective.

How do I set security headers on Cloudflare Workers Static Assets?▼

Create an extension-less public/_headers file with a /* path block listing headers like HSTS, X-Frame-Options, and Referrer-Policy. Cloudflare applies it only to static-asset responses; server-rendered routes need headers set in src/middleware.ts instead.

Why is my CSP not working in Astro dev mode?▼

Astro's native CSP does not run in astro dev because of the Vite dev server. Build the site and run astro preview, then inspect response headers and check the browser console for violations.

Does the Astro Cloudflare adapter support static headers?▼

No, @astrojs/cloudflare does not support the staticHeaders feature, so on static pages the CSP stays a meta element. Directives the meta element cannot carry, like frame-ancestors and report-to, must go in public/_headers as a separate CSP header.

Should I enable COEP require-corp on my static site?▼

Keep COEP off by default. require-corp breaks cross-origin embeds such as WebGL textures, Rive files, and third-party fonts unless every resource sends its own CORP or CORS header, so enable it only after confirming all cross-origin resources comply.

How do I add Subresource Integrity in Astro?▼

Astro has no native SRI, so add integrity attributes manually for one or two cross-origin resources, or use a small build-time script that fetches each pinned resource, computes its sha384 hash, and writes a JSON map your components render into tags.