Skip to content

Commit

Permalink
Merge pull request #79 from codergeek121/rename-csp-meta-tag-attribute
Browse files Browse the repository at this point in the history
Add content nonce meta-tag attribute fallback
  • Loading branch information
marcelolx authored Oct 9, 2024
2 parents 7e77fb3 + f9d8834 commit ea24d2d
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 ea24d2d

Please sign in to comment.