Skip to content

Commit

Permalink
Replace isIslandRequest util with check if nonce already exist
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Sthamer <[email protected]>
  • Loading branch information
P4sca1 committed Aug 3, 2024
1 parent b0b4a08 commit 57ff90b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/runtime/nitro/plugins/40-cspSsrNonce.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { defineNitroPlugin } from '#imports'
import { randomBytes } from 'node:crypto'
import { resolveSecurityRules } from '../context'
import { isIslandRequest } from '../../../utils/island'

const LINK_RE = /<link([^>]*?>)/gi
const SCRIPT_RE = /<script([^>]*?>)/gi
Expand All @@ -20,10 +19,10 @@ export default defineNitroPlugin((nitroApp) => {

// Genearate a 16-byte random nonce for each request.
nitroApp.hooks.hook('request', (event) => {
if (isIslandRequest(event)) {
if (event.context.security?.nonce) {
// When rendering server-only (NuxtIsland) components, each component will trigger a request event.
// The request context is shared between the event that renders the actual page and the island request events.
// We only generate the nonce once for the page event.
// Make sure to only generate the nonce once.
return
}

Expand Down
5 changes: 0 additions & 5 deletions src/utils/island.ts

This file was deleted.

0 comments on commit 57ff90b

Please sign in to comment.