From f9d8834bf40e968881959c823895f453a3cf0daa Mon Sep 17 00:00:00 2001 From: Niklas Haeusele Date: Mon, 30 Sep 2024 22:05:32 +0200 Subject: [PATCH] Add content nonce meta-tag attribute fallback --- src/fetch_response.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fetch_response.js b/src/fetch_response.js index 8f853a0..4123b10 100644 --- a/src/fetch_response.js +++ b/src/fetch_response.js @@ -81,8 +81,10 @@ export class FetchResponse { if (this.isScript) { const script = document.createElement('script') const metaTag = document.querySelector('meta[name=csp-nonce]') - const nonce = metaTag && metaTag.content - if (nonce) { script.setAttribute('nonce', nonce) } + if (metaTag) { + const nonce = metaTag.nonce === '' ? metaTag.content : metaTag.nonce + if (nonce) { script.setAttribute('nonce', nonce) } + } script.innerHTML = await this.text document.body.appendChild(script) } else {