Lorixen.
EN

Content Security Policy for a small business site: how-to

Short answer: A Content Security Policy (CSP) is a response header that tells browsers which scripts, styles, images and frames your pages may load, mainly to limit the damage if someone manages to inject malicious code. Start in report-only mode, collect violations for a week or two, adjust the policy to cover the tools you genuinely use, then switch to enforcement. Small sites break CSPs most often through inline scripts and third-party widgets.

Security scanners, hosting dashboards and agency audits regularly flag "missing Content-Security-Policy header". It's a reasonable recommendation, but switching it on carelessly can break your contact form, analytics or booking widget in one go. This step-by-step guide shows how to roll one out safely on a small business site.

What CSP does

MDN's guide to Content Security Policy describes it as a set of instructions from a website to the browser, restricting what the site's code is allowed to do. Its primary use is controlling which resources, especially JavaScript, a page can load, mainly as a defence against cross-site scripting (XSS), where an attacker injects malicious code into your site. MDN adds that a CSP can also help defend against clickjacking and help ensure pages load over HTTPS.

A policy is a list of directives. MDN's example:

Content-Security-Policy: default-src 'self'; img-src 'self' example.com

Here default-src 'self' allows resources only from your own origin by default, and img-src additionally allows images from example.com.

A strict policy can block inline script tags, inline event handlers and javascript: URLs, and allow only scripts carrying the correct nonce or hash. MDN notes the 'unsafe-inline' keyword can override the inline restriction, at the cost of much of the protection.

Step 1: inventory what your pages load

Before writing a policy, list what each type of page actually uses:

  • Your own scripts and stylesheets
  • Analytics and tag manager
  • Fonts (self-hosted or from a font service)
  • Embedded maps, videos, booking widgets, chat widgets, review badges
  • Payment or checkout scripts
  • Forms posting to third-party services
  • Images from a CDN

Your browser's developer tools (Network tab) show the domains each page contacts. Do this for the homepage, a typical content page, the contact or booking page and the checkout if you have one.

Step 2: write a first draft policy

Start with your own origin as the default, then add sources directive by directive:

  • script-src: your domain plus analytics, tag manager, payment and widget domains
  • style-src: your domain plus any font or widget style sources
  • img-src: your domain, CDN, analytics pixels, map tiles
  • font-src: self-hosted or font service domains
  • frame-src: embedded maps, videos, booking or payment frames
  • connect-src: endpoints your scripts call (analytics collection, form handlers, chat)
  • frame-ancestors: who may embed your site in a frame. MDN describes this as an effective protection against clickjacking; 'self' or 'none' suits most small sites.

Vendors often publish the domains their tools need for CSP; check each tool's documentation.

Step 3: deploy in report-only mode

MDN explains that CSP can be deployed in report-only mode: the policy isn't enforced, but violations are reported. The Content-Security-Policy-Report-Only header exists for this, letting you test or repair violations before applying an enforced policy. MDN notes that the report-to directive must be specified for reports to be sent, with endpoints defined in a Reporting-Endpoints response header; the older report-uri directive is deprecated but still seen. It also notes the report-only header isn't supported inside a <meta> element, so set it as an HTTP header at your server, host or CDN.

Even without a reporting endpoint, violations appear in the browser console as you browse the site, which is enough for a small site's first pass.

Step 4: read the violations and adjust

For each reported violation, decide:

  • Legitimate and needed? Add the source to the right directive.
  • Inline script? Move it into a file, or use a nonce or hash if your platform supports them. Avoid reaching for 'unsafe-inline' as a first fix.
  • Unknown or unwanted? Investigate. It may be an old tracking script, a browser extension (those can be ignored), or something that shouldn't be there.

Repeat until normal use of the site produces no violations you care about. Give it at least a week of real traffic if you can.

Step 5: enforce

Switch the header name to Content-Security-Policy, keep a report-only copy of any stricter future policy if you want to keep improving, and test key journeys straight away: forms, checkout, bookings, maps, chat, analytics.

Step 6: maintain it

  • Adding a new tool? Update the policy as part of the installation, not after something breaks.
  • Removing a tool? Remove its domains so the policy stays tight.
  • Platform updates? CMS, theme or plugin updates can introduce new inline scripts; recheck after major updates.

Troubleshooting common breakages

  • Contact form stops sending: the form posts to, or loads scripts from, a domain missing from form-action, connect-src or script-src.
  • Analytics shows a drop: analytics collection endpoints are missing from connect-src or img-src.
  • Embedded map or video is blank: add the provider to frame-src.
  • Fonts fall back to defaults: the font host is missing from font-src (and sometimes style-src).
  • Page builder features broken: many builders rely on inline scripts or styles; check what nonce or hash support your platform offers.

Other headers often flagged alongside CSP

Scanners usually list a few companions, such as HTTP Strict Transport Security, X-Content-Type-Options and Referrer-Policy. Each is simpler than CSP; read MDN's page for each before switching it on.

FAQ

Will a CSP slow my site down?

No meaningful effect on speed; the browser simply checks resources against the policy. The work is in getting the policy right.

Can I set CSP with a meta tag?

Some CSP directives can be delivered in a <meta> element, but MDN notes the report-only header can't, and features such as frame-ancestors need the HTTP header. Prefer the header.

My WordPress site uses lots of plugins. Is CSP realistic?

Yes, but expect more report-only iterations. Plugin-heavy sites often need 'unsafe-inline' for styles at first; tighten over time.

Does CSP replace keeping plugins updated?

No. It limits damage if something is injected; it doesn't fix vulnerabilities. Updates and good access controls still come first.

Got a scanner report flagging missing security headers and worried about breaking your site? Send it over and we'll plan a report-only rollout with you.

Sources

WhatsAppLet’s talk