CookieHub Docs

Content Security Policy (CSP)

If you implemented the CookieHub CSP before version 2.8.4, you might need to update your CSP configuration. Starting with version 2.8.4, the cdn.cookiehub.eu and cookiehub.net hosts must be included in the connect-src directive.

Content Security Policy (CSP) is an added layer of security that helps detect and mitigate certain types of attacks on websites. It essentially specifies from which domains the browser is allowed to load resources. More information: Content Security Policy (CSP)

Access to the following domains are required for CookieHub to function correctly:

  • cookiehub.net
  • ds.cookiehub.net
  • consent.cookiehub.net
  • cdn.cookiehub.eu
  • region-eu.cookiehub.net
  • consent-eu.cookiehub.net

If you have CSP enabled on your website and are currently using CookieHub, or planning to do so, you should add the following to your CSP configuration:

Content-Security-Policy: script-src cookiehub.net cdn.cookiehub.eu; style-src cookiehub.net cdn.cookiehub.eu 'unsafe-inline'; connect-src ds.cookiehub.net consent.cookiehub.net region-eu.cookiehub.net consent-eu.cookiehub.net cookiehub.net cdn.cookiehub.eu

The install snippet also contains a small inline script that calls cookiehub.load(). If your script-src already contains 'unsafe-inline', or you install CookieHub through Google Tag Manager, nothing more is needed. If your script-src uses a nonce, add the same nonce to both CookieHub script tags (see Using a nonce). Otherwise, add 'unsafe-inline' to script-src or use a nonce: without either, the CookieHub script loads but the consent dialog never appears.

If the Amazon Consent Signal integration is enabled, CookieHub also loads Amazon's consent library, so add c.amazon-adsystem.com to script-src.

Google Tag Manager

When CookieHub is installed with the Google Tag Manager template, there is no inline snippet. If your policy uses a nonce, put it on Google Tag Manager's container snippet as Google describes; Google Tag Manager passes it on to the CookieHub script. This works with and without 'strict-dynamic'.

Using a nonce

A nonce is a random value your server generates for every response, sends in the policy and sets on the script tags. Add it to both CookieHub script tags:

<script src="https://cdn.cookiehub.eu/c2/XXXXXXXX.js" nonce="{RANDOM}"></script>
<script type="text/javascript" nonce="{RANDOM}">
document.addEventListener("DOMContentLoaded", function(event) {
    var cpm = {};
    window.cookiehub.load(cpm);
});
</script>

With the nonce on both tags, 'strict-dynamic' works too. It makes browsers ignore the host entries in script-src, so the nonce is what allows the CookieHub script. A hash of the inline script works instead of a nonce, but it has to be recalculated whenever the snippet changes.

Microsoft UET

If the Microsoft UET integration is enabled, CookieHub sets UET's default consent with an inline script of its own, which the nonce on the install snippet does not cover. With a nonce but neither 'unsafe-inline' nor 'strict-dynamic' in script-src, this script is blocked: the consent dialog works, but UET gets no consent default. Add 'strict-dynamic' or 'unsafe-inline' to script-src. A future widget version removes the need for this.

Inline styles

CookieHub applies some of its styling with inline styles, so style-src needs 'unsafe-inline' on every widget version. What breaks without it depends on the version:

  • Before 2.9: your custom colours for buttons and toggles fall back to the default blue, and the cookie declaration loses its column labels on mobile.
  • 2.9 and later: the consent dialog and the preference center look and work the same, but the browser console reports CSP violations when the preference center opens.

A future widget version removes the need for 'unsafe-inline' in style-src.

Example policies

With a nonce and host entries:

Content-Security-Policy: script-src 'nonce-{RANDOM}' cookiehub.net cdn.cookiehub.eu; style-src cookiehub.net cdn.cookiehub.eu 'unsafe-inline'; connect-src ds.cookiehub.net consent.cookiehub.net region-eu.cookiehub.net consent-eu.cookiehub.net cookiehub.net cdn.cookiehub.eu

With a nonce and 'strict-dynamic':

Content-Security-Policy: script-src 'nonce-{RANDOM}' 'strict-dynamic'; style-src cookiehub.net cdn.cookiehub.eu 'unsafe-inline'; connect-src ds.cookiehub.net consent.cookiehub.net region-eu.cookiehub.net consent-eu.cookiehub.net cookiehub.net cdn.cookiehub.eu

Both need the nonce on the CookieHub script tags, as in Using a nonce.

On this page