Basic static site CSP template
For a simple site that serves its own scripts, styles, images, and fonts from the same origin.
Choose and copy a Content Security Policy template for your site type. Replace the example sources, review the inline-code strategy, and test the adapted policy in report-only mode before enforcement.
Choose by the resources and integrations your site needs, not only its framework. Start with the closest pattern and add only the sources you can justify:
Use the free CSP scanner and header generator to identify sources from reached pages. Replace placeholder origins, remove unneeded allowances, and review inline code. These templates are starting points; test representative flows with report-only CSP before enforcement.
Follow the worked template adaptation to see which directives change when a site adds an image host and an API.
For a simple site that serves its own scripts, styles, images, and fonts from the same origin.
For sites that rely on analytics, tag managers, hosted fonts, image CDNs, or embedded video.
For web apps that need script-src, connect-src, WebSocket endpoints, and asset CDN sources.
For checkout flows that must allow a payment provider while keeping script, frame, and connect sources tight.
For teams ready to remove broad inline allowances, reduce XSS risk, and trust specific inline code.
A useful example shows a restrictive fallback such as default-src; deliberate protections such as base-uri, object-src, and frame-ancestors; the resource directives its site type needs; clearly marked placeholder origins; and a deliberate inline-code strategy. Use the CSP directive glossary for definitions and CSP header examples by platform for delivery syntax.
Hypothetical example: A site serves its JavaScript and styles from its own origin, displays images from https://images.example, and calls https://api.example. These are assumed requirements for this exercise, not a customer scan or deployment result. It has no required inline code or embedded frames.
This candidate does not yet allow the separate image host or API.
The script and style rules retain their same-origin restriction.
img-src and the API origin in connect-src, rather than allowing both hosts under default-src.These snippets are policy values. Use platform header examples to deliver them, and keep a rollback path when you move to enforcement.
A bounded scan can separate the Google tag script from analytics beacons instead of adding every Google domain to every directive. The exact evidence depends on consent state, enabled GA4 features, linked advertising products, regional collection endpoints, and the user flows reached during the scan.
gtag.js → script-src
A request to www.googletagmanager.com belongs in the script source list.
measurement fetch → connect-src
GA4 collection requests can use *.google-analytics.com and *.analytics.google.com.
measurement pixel → img-src
Image-style beacons belong in img-src, not connect-src.
inline bootstrap → nonce or hash
The inline Google tag or Tag Manager bootstrap needs deliberate inline-script authorization; do not add 'unsafe-inline' by reflex.
This example uses script-src so it also supplies the fallback for script elements. Applications that split script-src-elem and script-src should place sources deliberately in both layers.
Allow same-origin JavaScript and one reviewed CDN while keeping inline script disabled.
Allow API, fetch, XHR, and WebSocket traffic only to expected application endpoints.
Allow same-origin images, reviewed image CDNs, and small inline data images when needed.
Block other sites from embedding your page unless you explicitly allow a parent origin.
Use a fresh, unpredictable nonce per response when your server can inject the nonce into trusted script tags.
Use hashes when inline script or style blocks are stable and can be hashed during build or scan review.
base-uri, object-src, and frame-ancestors.'unsafe-inline' or 'unsafe-eval' in place permanently.* or broad wildcards for convenience.connect-src for API, fetch, or WebSocket traffic.No. Treat examples as a starting point. Scan your site, compare loaded resources, and test with report-only CSP before enforcement.
Yes, when the application genuinely spans those patterns. Combine only the source allowances and inline-code mechanisms required by observed and known flows; do not union every allowance from each template, and retain a deliberate restrictive baseline.
'unsafe-inline'?Some sites still rely on inline styles or scripts. Stronger policies should replace broad inline allowances with hashes, nonces, or code changes where practical.
Examples explain common CSP shapes, but Script Sentinel can load selected public pages in Chrome and build an editable policy candidate from the resources it observes.