Basic static site CSP template
For a simple site that serves its own scripts, styles, images, and fonts from the same origin.
Compare and adapt practical Content Security Policy examples for common site architectures, then scan your actual pages before deployment.
Choose the example closest to your site's architecture. Replace every placeholder origin with an origin the site actually uses, remove unneeded source allowances, externalize inline code where practical or choose a deliberate nonce or exact-hash strategy, and exercise representative flows with report-only CSP before enforcement.
Use the static template for same-origin brochure or documentation sites; SaaS or marketing for analytics, hosted fonts, and embeds; app and API for external APIs, WebSockets, and asset CDNs; ecommerce for payment scripts and frames; and strict nonce or hash examples when the response or build system can authorize 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.
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 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.