Skip to content

Commit

Permalink
Add content nonce meta-tag attribute fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
codergeek121 committed Sep 30, 2024
1 parent f3460a1 commit 493409e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/fetch_response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 493409e

Please sign in to comment.