diff --git a/src/runtime/nitro/plugins/40-cspSsrNonce.ts b/src/runtime/nitro/plugins/40-cspSsrNonce.ts index 6cf32f34..1f8f2321 100644 --- a/src/runtime/nitro/plugins/40-cspSsrNonce.ts +++ b/src/runtime/nitro/plugins/40-cspSsrNonce.ts @@ -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 = /]*?>)/gi const SCRIPT_RE = /]*?>)/gi @@ -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 } diff --git a/src/utils/island.ts b/src/utils/island.ts deleted file mode 100644 index 9edda5aa..00000000 --- a/src/utils/island.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { H3Event } from 'h3' - -export function isIslandRequest(event: H3Event) { - return event.path.startsWith('/__nuxt_island/') -} \ No newline at end of file