Skip to content

Commit

Permalink
fix(nonce): set nonce value when using ssg
Browse files Browse the repository at this point in the history
  • Loading branch information
trijpstra-fourlights committed Jul 18, 2023
1 parent 4cb390a commit b25342d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/runtime/nitro/plugins/cspNonce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export default <NitroAppPlugin> function (nitro) {

if (!nonce) { return }

// Replace nonce attribute in http-equiv meta tag
html.head = html.head.map((meta) => {
if (!meta.startsWith('<meta http-equiv="Content-Security-Policy"')) { return meta }
return meta.replaceAll('{{nonce}}', nonce)
})

// Add nonce attribute to all link tags
html.head = html.head.map(link => link.replaceAll(tagNotPrecededByQuotes('link'), `<link nonce="${nonce}"`))
html.bodyAppend = html.bodyAppend.map(link => link.replaceAll(tagNotPrecededByQuotes('link'), `<link nonce="${nonce}"`))
Expand Down

0 comments on commit b25342d

Please sign in to comment.