diff --git a/package.json b/package.json index 2c161430..535f00d5 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "dependencies": { "@nuxt/kit": "^3.8.0", "basic-auth": "^2.0.1", + "cheerio": "^1.0.0-rc.12", "defu": "^6.1.1", "nuxt-csurf": "^1.3.1", "pathe": "^1.0.0", @@ -59,10 +60,10 @@ "xss": "^1.0.14" }, "devDependencies": { + "@nuxt/eslint-config": "^0.2.0", "@nuxt/module-builder": "^0.5.2", "@nuxt/schema": "^3.8.0", "@nuxt/test-utils": "^3.8.0", - "@nuxt/eslint-config": "^0.2.0", "@types/node": "^18.18.1", "eslint": "^8.50.0", "nuxt": "^3.8.0", diff --git a/src/runtime/nitro/plugins/02-cspSsg.ts b/src/runtime/nitro/plugins/02-cspSsg.ts index a9161f0f..cfa22c1c 100644 --- a/src/runtime/nitro/plugins/02-cspSsg.ts +++ b/src/runtime/nitro/plugins/02-cspSsg.ts @@ -2,14 +2,12 @@ import path from 'node:path' import crypto from 'node:crypto' import type { H3Event } from 'h3' import defu from 'defu' -import type { - ModuleOptions -} from '../../../types' import type { ContentSecurityPolicyValue } from '../../../types/headers' import { defineNitroPlugin, useRuntimeConfig, getRouteRules } from '#imports' import { useNitro } from '@nuxt/kit' +import * as cheerio from 'cheerio' const moduleOptions = useRuntimeConfig().security @@ -17,7 +15,7 @@ export default defineNitroPlugin((nitroApp) => { nitroApp.hooks.hook('render:html', (html, { event }) => { // Content Security Policy - if (!isContentSecurityPolicyEnabled(event, moduleOptions)) { + if (!isContentSecurityPolicyEnabled(event)) { return } @@ -25,11 +23,6 @@ export default defineNitroPlugin((nitroApp) => { return } - // Detect bothe inline scripts and inline styles - const inlineScriptPattern = /]*>(.*?)<\/script>/gs - const inlineStylePattern = /