wowprompt

Content Security Policy header built for an existing site

Lists every script, style, font, image, frame and connection a site loads, then writes a Content Security Policy that allows exactly those, starting in report-only mode, with a rollout plan. Use it to harden a site against cross-site scripting without breaking analytics, payments or embedded videos.

A Content Security Policy header with each directive explained, a report-only version for testing, and a rollout plan in three stages
The output this prompt produced, unedited.

The prompt

Constraints first

  • No unsafe-inline or unsafe-eval for scripts; use nonces or hashes instead.
  • No wildcard sources such as https: or a bare *.
  • Start in report-only mode; never switch to enforce in the first step.
  • Allow only sources found in the material given.

Inputs

  • Page HTML from two or three key templates: [paste the head and any inline scripts]
  • Third-party services in use: [e.g. a tag manager, a payment widget, video embeds, a font service]
  • Where the header is set: [e.g. Nginx, Apache .htaccess, a framework middleware, CDN rules]
  • Report endpoint, if any: [e.g. a URL that collects reports, or none yet]

Work

  1. Build an inventory: | Resource | Type | Source host | Inline or external |
  2. Map each item to a directive: default-src, script-src, style-src, img-src, font-src, connect-src, frame-src, form-action, base-uri, frame-ancestors, object-src.
  3. Replace inline scripts with nonce or hash based loading.

Output format

  1. The report-only header, ready to paste for the server named.
  2. The final enforced header.
  3. Each directive with a one-line reason.
  4. A rollout plan: report-only, review reports for a week, enforce.
content security policycsp headerxss protectionsecurity headersreport only cspweb security

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity