klaro-js
klaro-js copied to clipboard
Support Content Security Policy (CSP) on inline scripts
Content Security Policy (CSP) blocks inline scripts unless a specific 'nonce' is added
Header: Content-Security-Policy: default-src 'none';script-src 'self' 'nonce-base64-value'
Html:
This patch work for us:
diff --git a/src/consent-manager.js b/src/consent-manager.js
index 7a117fd..e991b53 100644
--- a/src/consent-manager.js
+++ b/src/consent-manager.js
@@ -311,7 +311,9 @@ export default class ConsentManager {
for(const attribute of element.attributes){
newElement.setAttribute(attribute.name, attribute.value)
}
-
+ if (element.hasAttribute('nonce')) {
+ newElement.setAttribute('nonce', element.nonce)
+ }
newElement.innerText = element.innerText
newElement.text = element.text
i provided a pull request for that. #504