---
name: "strict-csp-nonce-builder"
description: "Eliminate XSS and unauthorized script execution with strict-nonce Content Security Policy."
metadata:
  author: "Google Web.dev"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "configure strict csp nonce"
  - "add content security policy nextjs"
  - "setup csp report-to"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Content Security Policy (CSP) Strict-Nonce Builder

Configures modern CSP Level 3 directives: script-src 'strict-nonce' 'strict-dynamic', object-src 'none', base-uri 'none', CSP violation reporting endpoints, and Next.js middleware headers.

## When to Invoke
Invoke this skill whenever you need to:
- configure strict csp nonce
- add content security policy nextjs
- setup csp report-to

## Execution SOP & Rules
1. Generate a cryptographically random base64 nonce (crypto.randomBytes(16)) on each request.
2. Define script-src 'nonce-<random>' 'strict-dynamic' 'unsafe-inline' https:; object-src 'none'; base-uri 'none'.
3. Inject the generated nonce attribute onto all server-rendered <script nonce="..."> tags.
4. Test policies using Content-Security-Policy-Report-Only before enforcing strictly.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
