Content Security Policy - CSP
A Content Security Policy (CSP) improves website security by helping to detect and mitigate certain types of attack, including XSS (Cross Site Scripting) attacks and content injection.
To let Eulerian work under a CSP, you need to:
- add a
noncetoken to the script calls in your HTML document. Your server generates this token at random on every request and injects it into the content returned. In our example, the token goes where{TOKEN_NONCE}is. - add the collection domain and the
nonceto script-src in yourContent-Security-PolicyMeta or HTTP Header.
CSP template
CSP meta or HTTP header
script-src mon.domainedetracking.com 'nonce-{TOKEN_NONCE}'
Script calls
<script nonce="{TOKEN_NONCE}">
(function(e,a){var i=e.length,y=5381,k='script',s=window,v=document,o=v.createElement(k);for(;i;){i-=1;y=(y*33)^e.charCodeAt(i)}y='_EA_'+(y>>>=0);(function(e,a,s,y){s[a]=s[a]||function(){(s[y]=s[y]||[]).push(arguments);s[y].eah=e;};}(e,a,s,y));i=new Date/1E7|0;o.ea=y;y=i%26;o.async=1;o.src='//'+e+'/'+String.fromCharCode(97+y,122-y,65+y)+(i%1E3)+'.js?2';s=v.getElementsByTagName(k)[0];s.parentNode.insertBefore(o,s);})
('mon.domainedetracking.com','EA_push');
</script>
<script nonce="{TOKEN_NONCE}">
EA_push();
</script>
Note
If you want to be able to use LiveTagging (which is strongly recommended, not least for customer support), you will also need to add the permission to the style-src of your CSP. The CSS files that handle the display of the LiveTagging window must be allowed to load.
Example with the token 3zs4IFgbAL
CSP meta or HTTP header
script-src mon.domainedetracking.com 'nonce-3zs4IFgbAL'
Script calls
<script nonce="3zs4IFgbAL">
(function(e,a){var i=e.length,y=5381,k='script',s=window,v=document,o=v.createElement(k);for(;i;){i-=1;y=(y*33)^e.charCodeAt(i)}y='_EA_'+(y>>>=0);(function(e,a,s,y){s[a]=s[a]||function(){(s[y]=s[y]||[]).push(arguments);s[y].eah=e;};}(e,a,s,y));i=new Date/1E7|0;o.ea=y;y=i%26;o.async=1;o.src='//'+e+'/'+String.fromCharCode(97+y,122-y,65+y)+(i%1E3)+'.js?2';s=v.getElementsByTagName(k)[0];s.parentNode.insertBefore(o,s);})
('mon.domainedetracking.com','EA_push');
</script>
<script nonce="3zs4IFgbAL">
EA_push();
</script>
Examples of working CSPs
With script-src 'self' foo.bar.com;, the remote script is valid:
<script src="//foo.bar.com/file.js" />
and the inline script is blocked:
<script>console.log('Hello');</script>
With script-src 'self' foo.bar.com 'nonce-xxxx';, both are valid, since the inline script carries the token:
<script src="//foo.bar.com/file.js" />
<script nonce="xxxx">
console.log('Hello');
</script>
With script-src 'self' foo.bar.com 'unsafe-inline';, both are valid, with no token:
<script src="//foo.bar.com/file.js" />
<script>
console.log('Hello');
</script>
Third-party tags and the nonce token
The nonce method lets us pass the nonce token on through Tag Management. For better compatibility, we recommend also adding the third-party tags’ domains to your CSP: with “ad hoc” tags, there is no guarantee that the nonce is implemented correctly.