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.
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
Build an inventory: | Resource | Type | Source host | Inline or external |
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.
Replace inline scripts with nonce or hash based loading.
Output format
The report-only header, ready to paste for the server named.
The final enforced header.
Each directive with a one-line reason.
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.