Skip to content
Advertisement

adding nonce to script tag for 3rd party code that breaks ‘unsafe-eval’

We are using netlify-cms that unfortunately emits code that break CONTENT-SECURITY-POLICY 'unsafe-eval'.

I have tried adding nonce attributes to all the script tags using nginx sub_filter:

JavaScript

I then add the nonce to the header also

JavaScript

I can see that the nonces in the script tags and the header all match:

JavaScript

header

JavaScript

But I still get the error message:

EvalError: Refused to evaluate a string as JavaScript because ‘unsafe-eval’ is not an allowed source of script in the following Content Security Policy directive: “script-src ‘self’ ‘nonce-77Fdz6e1aBiGr5b8qcReeUgkO2NtJnSm’

Advertisement

Answer

By using 'nonce-value' you can get rid of 'unsafe-inline' only, but not of 'unsafe-eval'.

'unsafe-eval' in Netlify is required to compile JSON to JS code, but you can get rid of 'unsafe-eval' too. Just update ajv-json-loader to use AJV 7 and Standalone mode and configure webpack config to use the updated loader. See nitty-gritty here.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement