The CSP is no more restrictive than the one used by this forum page (granted, the lists are different but restrictive non the less which is a good thing). We are open to changing the CSP on the site but need help understanding what needs to change or possibly how to deploy Webpushr in an alternative way. The browser error regarding the CSP is this:
Refused to execute inline event handler because it violates the following Content Security Policy directive: … Either the ‘unsafe-inline’ keyword, a hash (‘sha256-…’), or a nonce (‘nonce-…’) is required to enable inline execution.
We are not willing to change the CSP to enable unsafe-inline
. This would be a big security risk for any site and I think why is self explanatory but to prove that point: Google search results for “csp should i enable unsafe-inline”.
The other 2 options seem to be using a nonce
or providing a hash
but given that the script inlining occurs out of our execution control I do not believe this is possible.
How we currently have set this up (see below). Is there an alternate configuration that will allow this to work where we would not have to add script-src: unsafe-inline
?
Thank you in advance,
-Igor
POC HTML page demopushr.html
<html>
<head></head>
<body>
<h1>Demo</h1>
<!-- a hash is provided in the CSP for this script: sha256-3lSTGUZawbckE01O/wREJmT57/nl9ZNyPmzBJ5URy5s= -->
<!-- start webpushr tracking code-->
<script>(function(w,d, s, id) {if(typeof(w.webpushr)!=='undefined') return;w.webpushr=w.webpushr||function(){(w.webpushr.q=w.webpushr.q||[]).push(arguments)};var js, fjs = d.getElementsByTagName(s)[0];js = d.createElement(s); js.id = id;js.async=1;js.src = "https://cdn.webpushr.com/app.min.js";
fjs.parentNode.appendChild(js);}(window,document, 'script', 'webpushr-jssdk'));
webpushr('setup',{'key':'key_here' });
</script>
<!-- end webpushr tracking code -->
</body>
</html>
webpushr-sw.js
importScripts('https://cdn.webpushr.com/sw-server.min.js');
Trimmed down CSP header for the purposes of this POC
style-src 'self' https://bot.webpushr.com https://cdn.webpushr.com https://analytics.webpushr.com;
script-src 'self' 'sha256-3lSTGUZawbckE01O/wREJmT57/nl9ZNyPmzBJ5URy5s=' https://bot.webpushr.com https://cdn.webpushr.com https://analytics.webpushr.com;
img-src 'self' data: https://bot.webpushr.com https://cdn.webpushr.com https://analytics.webpushr.com;
connect-src 'self' https://bot.webpushr.com https://analytics.webpushr.com;
font-src 'self';
default-src 'self';
frame-src 'self';
block-all-mixed-content;
object-src 'none'