Open duhdugg opened 1 year ago
Hey there
Have you tried to pass the nonce param in the init() function?
const siteId = 123;
const hotjarVersion = 6;
const initOptions = {
debug: false,
nonce: true
}
Hotjar.init(siteId, hotjarVersion, initOptions);
If it does not help, please give more context around your issue
Yes, I am passing that option. What more context would be helpful?
btw, the nonce option being passed matches the value sent in our CSP header. In your example you have nonce as a boolean, which is incorrect.
With the following CSP header:
default-src 'self';
img-src 'self' https://static.hotjar.com https://script.hotjar.com https://www.hotjar.com;
connect-src 'self' https://*.hotjar.com https://*.hotjar.io wss://*.hotjar.com;
font-src 'self' https://script.hotjar.com;
script-src 'self' https://static.hotjar.com https://script.hotjar.com nonce-rAnd0m;
style-src 'self' https://static.hotjar.com https://script.hotjar.com nonce-rAnd0m
...I am initializing Hotjar with:
Hotjar.init(siteId, hotjarVersion, {
debug: false,
nonce: "rAnd0m",
});
The problem is that while the initial javascript loads with nonce values correctly, additional inline scripts (and styles) are created by Hotjar which do not include the nonce value initially passed to Init
. In my original post I point out where in the Hotjar javascript code that is happening.
The only solution I can find right now is to abandon nonces entirely and use 'unsafe-inline'
, which has a lot of security implications.
Running with the nonce option and appropriate CSP headers set, I am still seeing some blocking happening because the nonce is not used for every
<script>
and<style>
created by Hotjar.Here is the offending Hotjar code I'm seeing where a script element is created and appended without setting the nonce value:
Here is the offending Hotjar code I'm seeing where a style element is created without a nonce value. Follow along to see that
Ar
is passing the nonce toLn
, which is setting the attribute correctly, but the nonce is never passed toAr
when definingHr
.