Pilotiko feature : available

Content Security Policy: how do you limit what your website is allowed to load?

A guest list for your web page: anything not on the list stays outside.

A Content Security Policy (CSP) is a set of instructions a website sends to the browser, usually in the Content-Security-Policy HTTP header, restricting which resources a page may load and what it may do. Its main purpose is to limit the damage from cross-site scripting (XSS) injection and from clickjacking attempts.

Try 30 days free

30 days free, no credit card.

By Pilotiko editorial team · Updated on

In short

  • A policy is a series of directives separated by semicolons, such as default-src 'self'.
  • It should accompany every response, not just the main page.
  • frame-ancestors stops other sites from displaying your pages in a frame.
  • The Content-Security-Policy-Report-Only header lets you test without blocking anything.
  • Google Analytics requires specific domains in script-src-elem, img-src and connect-src.

What does a CSP protect against?

MDN says the main use of a CSP is to control which resources, JavaScript in particular, a document may load, as a defence against cross-site scripting (XSS) [1]. In an XSS attack, someone gets their own code to run inside your page, for example through a poorly filtered form field or URL parameter. That code can then read or change page content, or send requests on the visitor's behalf [1].

MDN is clear that sanitizing input remains the first line of defence; a CSP is defence in depth that limits the harm when sanitizing fails [1]. It also guards against clickjacking, where a malicious site shows yours inside an invisible frame, and can help ensure resources load over HTTPS [1].

The reference specification is published by the W3C; Content Security Policy Level 3 currently has Working Draft status [2].

Which directives make up a CSP?

The policy travels in the Content-Security-Policy response header and should be set on every response [1]. It can also sit in a <meta http-equiv> tag, though that route doesn't support every feature [1]. MDN describes frame-ancestors as a more flexible replacement for the older X-Frame-Options header [1].

Common Content Security Policy directives
DirectiveWhat it controlsCautious value for a business website
default-srcFallback rule for every resource type'self' (same origin only)
script-srcAllowed JavaScript files'self' plus the domains of tools you actually use
img-srcImage sources'self' and any image domains you need
connect-srcRequests sent by scripts'self' and measurement services, if any
frame-ancestorsWho may show the page inside a frame'none' or 'self'
upgrade-insecure-requestsUpgrades http:// resources to HTTPSOn if http:// links linger

Source: MDN [1]. The cautious values are suggestions to adapt to each site.

How do you roll out a CSP without breaking your site?

MDN describes a careful approach: publish the policy first in the Content-Security-Policy-Report-Only header [1]. The browser then reports what it would have blocked without blocking anything. You adjust the list, then switch to the enforcing header.

For scripts written directly into the HTML, Google's recommended method for Tag Manager is a nonce: a random, unguessable value the server generates for each response and adds to both the directive and the <script> tag [3]. The 'unsafe-inline' option exists, but Google presents it as a fallback only when a nonce or hash isn't workable [3].

What must you allow to add a measurement tool?

Which CSP mistakes should you avoid?

  • Shipping a strict policy with no report-only trial, so the quote form or the embedded map stops working [1].
  • Adding 'unsafe-inline' to script-src for convenience, which badly weakens protection against injected scripts.
  • Allowing an entire domain with a wildcard (*) without knowing what it hosts.
  • Setting the CSP on the home page only, when it should accompany every response [1].
  • Forgetting to update the policy when you add a tool, such as a booking widget or Google Analytics 4.
  • Relying on the CSP instead of validating and sanitizing form input [1].

Is a CSP connected to Quebec's Law 25?

Indirectly. Every domain allowed in connect-src or script-src is an outside service that may receive data from your visitors. Keeping that list current tells you which tools collect information, which helps you write an accurate privacy policy in the spirit of Law 25. Our Law 25 guide covers the actual obligations; a CSP isn't one of them in itself.

What does Pilotiko do with Content Security Policy?

The site Pilotiko hosts is served with a restrictive Content Security Policy: default-src 'self', scripts and stylesheets limited to the site itself, images from the site or over HTTPS, forms posting only to the site, frame-ancestors 'none' and base-uri 'none'. It also sends the X-Frame-Options DENY header. No third-party script is loaded, and adding Google Analytics to the site isn't offered yet: that feature is listed as coming soon.

Frequently asked questions

Is a CSP worth it for a small business website?

Yes, especially if it has a form. Even a simple site can load third-party scripts or be framed by another site; a CSP limits those risks at little cost.

Can a CSP break my website?

Yes, if it blocks a resource you need, such as a map or booking script. That is why you test it first with the Content-Security-Policy-Report-Only header.

CSP in a meta tag or in a header?

The HTTP header is the recommended route and supports every feature. The meta tag helps when you have no server access, but some directives don't work that way.

Do I still need X-Frame-Options alongside frame-ancestors?

MDN describes frame-ancestors as a more flexible replacement for X-Frame-Options. Nothing stops you from sending both, as long as they say the same thing.

What does 'self' mean in a CSP?

It is the page's own origin, in other words your own site. default-src 'self' means that by default the page only loads resources from your website.

Sources

  1. MDN Web Docs, Content Security Policy (CSP) (accessed on October 15, 2026).
  2. W3C, Content Security Policy Level 3 (Working Draft) (accessed on October 15, 2026).
  3. Google Tag Platform, Use Tag Manager with a Content Security Policy (accessed on October 15, 2026).

Your whole business, on one screen.

Each department is a room. Pilotiko prepares the work; you approve with one click.

Try 30 days free

The Pilotiko office of a sample company: each department is a room.
  • Call answered
  • Appointment confirmed
  • Email reply ready
  • Invoice prepared

Try the office with your team

30 days free.

Try 30 days free