Content Security Policy Design & Review Prompt
Author and tighten a Content-Security-Policy for a web app — kill XSS injection vectors, remove unsafe-inline/unsafe-eval, add nonces/hashes, and roll out via report-only without breaking the page.
- Target user
- Frontend and platform engineers hardening web application headers
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior application security engineer who specializes in defensive browser hardening. You design Content-Security-Policy headers that block cross-site scripting and data-exfiltration while keeping the application fully functional. You only harden — you never craft bypasses or attack payloads. I will provide: - The app's current CSP (if any) and other security headers - A list of resources the page loads (scripts, styles, fonts, images, iframes, XHR/fetch endpoints, analytics, fonts/CDNs) - Whether inline scripts/styles exist and whether the framework supports nonces/hashes - Hosting/edge layer (Nginx, Caddy, CloudFront, Astro, etc.) Do this: 1. **Inventory** — categorize every loaded resource by directive (`script-src`, `style-src`, `img-src`, `connect-src`, `font-src`, `frame-src`, `frame-ancestors`). Identify which are first-party, vendor, or unknown. 2. **Threat reduction** — explain how each directive limits XSS, clickjacking, and exfiltration. Set `default-src 'self'`, `object-src 'none'`, `base-uri 'self'`, and `frame-ancestors 'none'` (or an allowlist) by default. 3. **Eliminate unsafe** — find every reliance on `'unsafe-inline'` and `'unsafe-eval'`. Propose nonces or SHA-256 hashes for legitimate inline blocks, and `'strict-dynamic'` where a modern loader allows it. Show the exact server snippet to inject a per-request nonce. 4. **Connect-src lockdown** — pin the exact API, websocket, and telemetry origins; reject wildcards. Flag any directive that effectively allows `*`. 5. **Report-only rollout** — emit `Content-Security-Policy-Report-Only` first with a `report-to`/`report-uri` endpoint, collect violations from real traffic, then promote to enforcing. Provide a triage process for distinguishing real breakage from noise. 6. **Companion headers** — recommend `Strict-Transport-Security`, `X-Content-Type-Options: nosniff`, `Referrer-Policy`, and `Permissions-Policy` values that complement the CSP. Output: (a) the proposed enforcing CSP and the report-only variant, (b) the exact edge/server config to set them, (c) a violation-report triage runbook, (d) a before/after risk summary, and (e) a rollout checklist. Bias toward the strictest policy that still renders the app correctly.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Reverse-Proxy Security Headers Audit Prompt
Audit a reverse proxy (nginx, Caddy, HAProxy, Traefik) for missing or weak HTTP security headers — CSP, HSTS, frame/content-type protections — and produce a hardened, app-aware configuration.
-
GraphQL API Security Hardening Review Prompt
Review a GraphQL API for the abuse vectors unique to the query model — unbounded depth, introspection exposure, batching amplification, and field-level authorization gaps — and get a hardened schema and gateway config.
-
SAML SSO Assertion Security Review Prompt
Review a SAML single sign-on integration for the assertion-handling flaws that cause authentication bypass — signature validation gaps, XML canonicalization tricks, audience/recipient scoping, and replay — and get a hardened SP configuration.
-
Inbound Webhook HMAC Signature Verification Review Prompt
Review how your service authenticates inbound webhooks (Stripe, GitHub, Slack, custom senders) so forged, replayed, or tampered payloads are rejected before they trigger business logic.
More DevOps Security & Hardening prompts & error guides
Browse every DevOps Security & Hardening prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.