Instructions
Design CSP and companion headers (HSTS, X-Content-Type-Options, Referrer-Policy, Permissions-Policy, COOP) for Next.js. Read csp-headers.md before changing production headers.
When to Use
- Use when rolling out CSP, HSTS, or Permissions-Policy on App Router or Pages.
- Prefer
auth-handbookfirst if OAuth popups or cookies are already broken. - Prefer
observability-handbookwhen wiring CSP report endpoints (no PII dumps).
- Inventory inline scripts and styles; decide nonce vs hash strategy for App Router (see csp-headers.md).
- Start Content-Security-Policy-Report-Only with
report-toorreport-uriif used. - Third parties: list each script domain in
script-src; avoidunsafe-inlineunless a documented exception. - Prefer
next.configheaders vs middleware based on deployment (Vercel vs self-hosted). - Document break-glass: who can widen policy for an emergency hotfix.
- After enforce: verify hydration, images/fonts, and IdP
frame-srcfor OAuth.
Outcomes
- Header table + CSP lines + phased rollout (report-only → enforce).
Output Rules
Fenced blocks for next.config header snippets only after the user approves writes.
Scope and boundaries
- In scope: headers, CSP, Permissions-Policy for frontend.
- Out of scope: WAF vendor rules, DDoS provider setup.
Safety
- requires_user_approval: true - wrong CSP breaks production.
- Never paste real nonce secrets; use placeholders.
Troubleshooting
- CSP blocks hydration: check nonce on
next/scriptstrategy. - Images blocked: add
img-srcandmedia-srcas needed. - Login popup blank: widen
frame-src/form-actionfor the IdP carefully.
Related skills
auth-handbook- sessions before tightening CSPobservability-handbook- report endpoint hygiene
GitHub: https://github.com/bh611627/skillcodex/tree/main/skills/security-headers/SKILL.md
npm: https://www.npmjs.com/package/@skillcodex/skills