diff --git a/e2e/react-start/csp/.gitignore b/e2e/react-start/csp/.gitignore new file mode 100644 index 0000000000..f0450534a3 --- /dev/null +++ b/e2e/react-start/csp/.gitignore @@ -0,0 +1,4 @@ +node_modules +.output +dist +*.txt diff --git a/e2e/react-start/csp/package.json b/e2e/react-start/csp/package.json new file mode 100644 index 0000000000..90bea313cb --- /dev/null +++ b/e2e/react-start/csp/package.json @@ -0,0 +1,29 @@ +{ + "name": "tanstack-react-start-e2e-csp", + "private": true, + "sideEffects": false, + "type": "module", + "scripts": { + "dev": "vite dev --port 3000", + "dev:e2e": "vite dev", + "build": "vite build && tsc --noEmit", + "start": "pnpx srvx --prod -s ../client dist/server/server.js", + "test:e2e": "rm -rf port*.txt; playwright test --project=chromium" + }, + "dependencies": { + "@tanstack/react-router": "workspace:^", + "@tanstack/react-start": "workspace:^", + "react": "^19.0.0", + "react-dom": "^19.0.0", + "vite": "^7.1.7" + }, + "devDependencies": { + "@playwright/test": "^1.50.1", + "@tanstack/router-e2e-utils": "workspace:^", + "@types/node": "^22.10.2", + "@types/react": "^19.0.8", + "@types/react-dom": "^19.0.3", + "srvx": "^0.10.0", + "typescript": "^5.7.2" + } +} diff --git a/e2e/react-start/csp/playwright.config.ts b/e2e/react-start/csp/playwright.config.ts new file mode 100644 index 0000000000..5f9de5709e --- /dev/null +++ b/e2e/react-start/csp/playwright.config.ts @@ -0,0 +1,35 @@ +import { defineConfig, devices } from '@playwright/test' +import { getTestServerPort } from '@tanstack/router-e2e-utils' +import packageJson from './package.json' with { type: 'json' } + +const PORT = await getTestServerPort(packageJson.name) +const baseURL = `http://localhost:${PORT}` + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + testDir: './tests', + workers: 1, + + reporter: [['line']], + + use: { + /* Base URL to use in actions like `await page.goto('/')`. */ + baseURL, + }, + + webServer: { + command: `VITE_SERVER_PORT=${PORT} pnpm build && PORT=${PORT} VITE_SERVER_PORT=${PORT} pnpm start`, + url: baseURL, + reuseExistingServer: !process.env.CI, + stdout: 'pipe', + }, + + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + ], +}) diff --git a/e2e/react-start/csp/public/external.css b/e2e/react-start/csp/public/external.css new file mode 100644 index 0000000000..4085d14afd --- /dev/null +++ b/e2e/react-start/csp/public/external.css @@ -0,0 +1,4 @@ +.external-styled { + color: blue; + font-weight: bold; +} diff --git a/e2e/react-start/csp/public/external.js b/e2e/react-start/csp/public/external.js new file mode 100644 index 0000000000..9efb4f8769 --- /dev/null +++ b/e2e/react-start/csp/public/external.js @@ -0,0 +1,3 @@ +// This script sets a window global when loaded +// Using a global avoids race conditions with React and DOM ownership issues +window.__EXTERNAL_SCRIPT_LOADED__ = true diff --git a/e2e/react-start/csp/src/routeTree.gen.ts b/e2e/react-start/csp/src/routeTree.gen.ts new file mode 100644 index 0000000000..dceedffdc1 --- /dev/null +++ b/e2e/react-start/csp/src/routeTree.gen.ts @@ -0,0 +1,68 @@ +/* eslint-disable */ + +// @ts-nocheck + +// noinspection JSUnusedGlobalSymbols + +// This file was automatically generated by TanStack Router. +// You should NOT make any changes in this file as it will be overwritten. +// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. + +import { Route as rootRouteImport } from './routes/__root' +import { Route as IndexRouteImport } from './routes/index' + +const IndexRoute = IndexRouteImport.update({ + id: '/', + path: '/', + getParentRoute: () => rootRouteImport, +} as any) + +export interface FileRoutesByFullPath { + '/': typeof IndexRoute +} +export interface FileRoutesByTo { + '/': typeof IndexRoute +} +export interface FileRoutesById { + __root__: typeof rootRouteImport + '/': typeof IndexRoute +} +export interface FileRouteTypes { + fileRoutesByFullPath: FileRoutesByFullPath + fullPaths: '/' + fileRoutesByTo: FileRoutesByTo + to: '/' + id: '__root__' | '/' + fileRoutesById: FileRoutesById +} +export interface RootRouteChildren { + IndexRoute: typeof IndexRoute +} + +declare module '@tanstack/react-router' { + interface FileRoutesByPath { + '/': { + id: '/' + path: '/' + fullPath: '/' + preLoaderRoute: typeof IndexRouteImport + parentRoute: typeof rootRouteImport + } + } +} + +const rootRouteChildren: RootRouteChildren = { + IndexRoute: IndexRoute, +} +export const routeTree = rootRouteImport + ._addFileChildren(rootRouteChildren) + ._addFileTypes() + +import type { getRouter } from './router.tsx' +import type { createStart } from '@tanstack/react-start' +declare module '@tanstack/react-start' { + interface Register { + ssr: true + router: Awaited> + } +} diff --git a/e2e/react-start/csp/src/router.tsx b/e2e/react-start/csp/src/router.tsx new file mode 100644 index 0000000000..c8caf51e8d --- /dev/null +++ b/e2e/react-start/csp/src/router.tsx @@ -0,0 +1,20 @@ +import { createRouter } from '@tanstack/react-router' +import { createIsomorphicFn } from '@tanstack/react-start' +import { routeTree } from './routeTree.gen' + +const getSSROptions = createIsomorphicFn().server(() => { + const array = new Uint8Array(16) + crypto.getRandomValues(array) + const nonce = Array.from(array, (b) => b.toString(16).padStart(2, '0')).join( + '', + ) + return { nonce } +}) + +export function getRouter() { + return createRouter({ + routeTree, + scrollRestoration: true, + ssr: getSSROptions(), + }) +} diff --git a/e2e/react-start/csp/src/routes/__root.tsx b/e2e/react-start/csp/src/routes/__root.tsx new file mode 100644 index 0000000000..dabcb8ebc2 --- /dev/null +++ b/e2e/react-start/csp/src/routes/__root.tsx @@ -0,0 +1,47 @@ +import { + createRootRoute, + HeadContent, + Outlet, + Scripts, +} from '@tanstack/react-router' + +export const Route = createRootRoute({ + headers: ({ ssr }) => { + const nonce = ssr?.nonce + if (!nonce) return + return { + 'Content-Security-Policy': [ + "default-src 'self'", + `script-src 'self' 'nonce-${nonce}'`, + `style-src 'self' 'nonce-${nonce}'`, + ].join('; '), + } + }, + head: () => ({ + meta: [ + { charSet: 'utf-8' }, + { name: 'viewport', content: 'width=device-width, initial-scale=1' }, + { title: 'CSP Nonce Test' }, + ], + links: [{ rel: 'stylesheet', href: '/external.css' }], + scripts: [{ src: '/external.js' }], + styles: [ + { children: '.inline-styled { color: green; font-weight: bold; }' }, + ], + }), + component: RootComponent, +}) + +function RootComponent() { + return ( + + + + + + + + + + ) +} diff --git a/e2e/react-start/csp/src/routes/index.tsx b/e2e/react-start/csp/src/routes/index.tsx new file mode 100644 index 0000000000..bb765ce87c --- /dev/null +++ b/e2e/react-start/csp/src/routes/index.tsx @@ -0,0 +1,25 @@ +import { useState } from 'react' +import { createFileRoute } from '@tanstack/react-router' + +export const Route = createFileRoute('/')({ + component: Home, +}) + +function Home() { + const [count, setCount] = useState(0) + + return ( +
+

CSP Nonce Test

+

+ This should be green if inline styles work +

+

+ This should be blue if external styles work +

+ +
+ ) +} diff --git a/e2e/react-start/csp/tests/csp.spec.ts b/e2e/react-start/csp/tests/csp.spec.ts new file mode 100644 index 0000000000..5bdfd93e9b --- /dev/null +++ b/e2e/react-start/csp/tests/csp.spec.ts @@ -0,0 +1,170 @@ +import { expect } from '@playwright/test' +import { test } from '@tanstack/router-e2e-utils' + +test('CSP header is set with nonce', async ({ page }) => { + const response = await page.goto('/') + const csp = response?.headers()['content-security-policy'] + expect(csp).toContain("script-src 'self' 'nonce-") + expect(csp).toContain("style-src 'self' 'nonce-") +}) + +test('Inline scripts have nonce attribute', async ({ page }) => { + await page.goto('/') + const scripts = await page.locator('script[nonce]').all() + expect(scripts.length).toBeGreaterThan(0) +}) + +test('Inline styles have nonce attribute', async ({ page }) => { + await page.goto('/') + const styles = await page.locator('style[nonce]').all() + expect(styles.length).toBeGreaterThan(0) +}) + +test('External script has nonce attribute', async ({ page }) => { + await page.goto('/') + const externalScript = page.locator('script[src="/external.js"]') + await expect(externalScript).toHaveAttribute('nonce') +}) + +test('External stylesheet has nonce attribute', async ({ page }) => { + await page.goto('/') + const externalStylesheet = page.locator('link[href="/external.css"]') + await expect(externalStylesheet).toHaveAttribute('nonce') +}) + +test('Nonces match between header and elements', async ({ page }) => { + // Intercept the HTML response to get raw content before browser strips nonces + let rawHtml = '' + await page.route('/', async (route) => { + const response = await route.fetch() + rawHtml = await response.text() + await route.fulfill({ response }) + }) + + const response = await page.goto('/') + await page.unrouteAll({ behavior: 'ignoreErrors' }) + + const csp = response?.headers()['content-security-policy'] || '' + + // Extract nonce from CSP header + const nonceMatch = csp.match(/nonce-([a-f0-9]+)/) + expect(nonceMatch).toBeTruthy() + const headerNonce = nonceMatch![1] + + // Check script nonces match - look for nonce attribute anywhere in the script tag + const scriptNonces = [ + ...rawHtml.matchAll(/]*\bnonce="([^"]+)"[^>]*>/g), + ].map((m) => m[1]) + expect(scriptNonces.length).toBeGreaterThan(0) + for (const nonce of scriptNonces) { + expect(nonce).toBe(headerNonce) + } + + // Check style nonces match + const styleNonces = [ + ...rawHtml.matchAll(/]*\bnonce="([^"]+)"[^>]*>/g), + ].map((m) => m[1]) + expect(styleNonces.length).toBeGreaterThan(0) + for (const nonce of styleNonces) { + expect(nonce).toBe(headerNonce) + } + + // Check external script nonce matches (nonce can be before or after src) + const externalScriptMatch = rawHtml.match( + /]*\bsrc="\/external\.js"[^>]*\bnonce="([^"]+)"[^>]*>|]*\bnonce="([^"]+)"[^>]*\bsrc="\/external\.js"[^>]*>/, + ) + expect(externalScriptMatch).toBeTruthy() + expect(externalScriptMatch![1] || externalScriptMatch![2]).toBe(headerNonce) + + // Check external stylesheet nonce matches (nonce can be before or after href) + const externalStyleMatch = rawHtml.match( + /]*\bhref="\/external\.css"[^>]*\bnonce="([^"]+)"[^>]*>|]*\bnonce="([^"]+)"[^>]*\bhref="\/external\.css"[^>]*>/, + ) + expect(externalStyleMatch).toBeTruthy() + expect(externalStyleMatch![1] || externalStyleMatch![2]).toBe(headerNonce) +}) + +test('Hydration works - counter increments', async ({ page }) => { + await page.goto('/') + await expect(page.getByTestId('counter-value')).toContainText('0') + + // Keep clicking until React hydrates and the counter increments + // This handles the race between test execution and hydration + await expect + .poll( + async () => { + await page.getByTestId('counter-btn').click() + return page.getByTestId('counter-value').textContent() + }, + { timeout: 10000, intervals: [100, 200, 500, 1000] }, + ) + .not.toBe('0') + + // Now that hydration is confirmed, verify further increments work + const currentValue = parseInt( + (await page.getByTestId('counter-value').textContent()) || '0', + ) + await page.getByTestId('counter-btn').click() + await expect(page.getByTestId('counter-value')).toContainText( + String(currentValue + 1), + ) +}) + +test('Inline styles work with CSP', async ({ page }) => { + await page.goto('/') + const el = page.getByTestId('inline-styled') + await expect(el).toBeVisible() + // Verify the style was applied (green color) + const color = await el.evaluate((e) => getComputedStyle(e).color) + expect(color).toBe('rgb(0, 128, 0)') // green +}) + +test('External styles work with CSP', async ({ page }) => { + await page.goto('/') + const el = page.getByTestId('external-styled') + await expect(el).toBeVisible() + // Verify the style was applied (blue color) + const color = await el.evaluate((e) => getComputedStyle(e).color) + expect(color).toBe('rgb(0, 0, 255)') // blue +}) + +test('External script executes with CSP', async ({ page }) => { + await page.goto('/') + // Check that the external script set its window global + await expect + .poll(() => page.evaluate(() => (window as any).__EXTERNAL_SCRIPT_LOADED__)) + .toBe(true) +}) + +test('No CSP violations in console', async ({ page }) => { + const violations: string[] = [] + page.on('console', (msg) => { + if (msg.text().toLowerCase().includes('content security policy')) { + violations.push(msg.text()) + } + }) + page.on('pageerror', (err) => { + if (err.message.toLowerCase().includes('content security policy')) { + violations.push(err.message) + } + }) + await page.goto('/') + await page.getByTestId('counter-btn').click() + // Small wait to ensure any async violations are caught + await page.waitForTimeout(100) + expect(violations).toEqual([]) +}) + +test('Each request gets a unique nonce', async ({ page }) => { + const response1 = await page.goto('/') + const csp1 = response1?.headers()['content-security-policy'] || '' + const nonce1 = csp1.match(/nonce-([a-f0-9]+)/)?.[1] + + const response2 = await page.goto('/') + const csp2 = response2?.headers()['content-security-policy'] || '' + const nonce2 = csp2.match(/nonce-([a-f0-9]+)/)?.[1] + + expect(nonce1).toBeTruthy() + expect(nonce2).toBeTruthy() + expect(nonce1).not.toBe(nonce2) +}) diff --git a/e2e/react-start/csp/tsconfig.json b/e2e/react-start/csp/tsconfig.json new file mode 100644 index 0000000000..3a9fb7cd71 --- /dev/null +++ b/e2e/react-start/csp/tsconfig.json @@ -0,0 +1,22 @@ +{ + "include": ["**/*.ts", "**/*.tsx"], + "compilerOptions": { + "strict": true, + "esModuleInterop": true, + "jsx": "react-jsx", + "module": "ESNext", + "moduleResolution": "Bundler", + "lib": ["DOM", "DOM.Iterable", "ES2022"], + "isolatedModules": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "target": "ES2022", + "allowJs": true, + "forceConsistentCasingInFileNames": true, + "baseUrl": ".", + "paths": { + "~/*": ["./src/*"] + }, + "noEmit": true + } +} diff --git a/e2e/react-start/csp/vite.config.ts b/e2e/react-start/csp/vite.config.ts new file mode 100644 index 0000000000..275bfacde2 --- /dev/null +++ b/e2e/react-start/csp/vite.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from 'vite' +import { tanstackStart } from '@tanstack/react-start/plugin/vite' + +export default defineConfig({ + server: { + port: 3000, + }, + plugins: [tanstackStart()], +}) diff --git a/e2e/solid-start/csp/.gitignore b/e2e/solid-start/csp/.gitignore new file mode 100644 index 0000000000..a86a144649 --- /dev/null +++ b/e2e/solid-start/csp/.gitignore @@ -0,0 +1,5 @@ +node_modules +dist +.output +test-results +playwright-report diff --git a/e2e/solid-start/csp/package.json b/e2e/solid-start/csp/package.json new file mode 100644 index 0000000000..36ce4523d0 --- /dev/null +++ b/e2e/solid-start/csp/package.json @@ -0,0 +1,27 @@ +{ + "name": "tanstack-solid-start-e2e-csp", + "private": true, + "sideEffects": false, + "type": "module", + "scripts": { + "dev": "vite dev --port 3000", + "dev:e2e": "vite dev", + "build": "vite build && tsc --noEmit", + "start": "pnpx srvx --prod -s ../client dist/server/server.js", + "test:e2e": "rm -rf port*.txt; playwright test --project=chromium" + }, + "dependencies": { + "@tanstack/solid-router": "workspace:^", + "@tanstack/solid-start": "workspace:^", + "solid-js": "^1.9.10", + "vite": "^7.1.7" + }, + "devDependencies": { + "@playwright/test": "^1.50.1", + "@tanstack/router-e2e-utils": "workspace:^", + "@types/node": "^22.10.2", + "srvx": "^0.10.0", + "typescript": "^5.7.2", + "vite-plugin-solid": "^2.11.10" + } +} diff --git a/e2e/solid-start/csp/playwright.config.ts b/e2e/solid-start/csp/playwright.config.ts new file mode 100644 index 0000000000..5f9de5709e --- /dev/null +++ b/e2e/solid-start/csp/playwright.config.ts @@ -0,0 +1,35 @@ +import { defineConfig, devices } from '@playwright/test' +import { getTestServerPort } from '@tanstack/router-e2e-utils' +import packageJson from './package.json' with { type: 'json' } + +const PORT = await getTestServerPort(packageJson.name) +const baseURL = `http://localhost:${PORT}` + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + testDir: './tests', + workers: 1, + + reporter: [['line']], + + use: { + /* Base URL to use in actions like `await page.goto('/')`. */ + baseURL, + }, + + webServer: { + command: `VITE_SERVER_PORT=${PORT} pnpm build && PORT=${PORT} VITE_SERVER_PORT=${PORT} pnpm start`, + url: baseURL, + reuseExistingServer: !process.env.CI, + stdout: 'pipe', + }, + + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + ], +}) diff --git a/e2e/solid-start/csp/public/external.css b/e2e/solid-start/csp/public/external.css new file mode 100644 index 0000000000..4085d14afd --- /dev/null +++ b/e2e/solid-start/csp/public/external.css @@ -0,0 +1,4 @@ +.external-styled { + color: blue; + font-weight: bold; +} diff --git a/e2e/solid-start/csp/public/external.js b/e2e/solid-start/csp/public/external.js new file mode 100644 index 0000000000..35cb817064 --- /dev/null +++ b/e2e/solid-start/csp/public/external.js @@ -0,0 +1,3 @@ +// This script sets a window global when loaded +// Using a global avoids race conditions with Solid and DOM ownership issues +window.__EXTERNAL_SCRIPT_LOADED__ = true diff --git a/e2e/solid-start/csp/src/routeTree.gen.ts b/e2e/solid-start/csp/src/routeTree.gen.ts new file mode 100644 index 0000000000..4776246e1f --- /dev/null +++ b/e2e/solid-start/csp/src/routeTree.gen.ts @@ -0,0 +1,68 @@ +/* eslint-disable */ + +// @ts-nocheck + +// noinspection JSUnusedGlobalSymbols + +// This file was automatically generated by TanStack Router. +// You should NOT make any changes in this file as it will be overwritten. +// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. + +import { Route as rootRouteImport } from './routes/__root' +import { Route as IndexRouteImport } from './routes/index' + +const IndexRoute = IndexRouteImport.update({ + id: '/', + path: '/', + getParentRoute: () => rootRouteImport, +} as any) + +export interface FileRoutesByFullPath { + '/': typeof IndexRoute +} +export interface FileRoutesByTo { + '/': typeof IndexRoute +} +export interface FileRoutesById { + __root__: typeof rootRouteImport + '/': typeof IndexRoute +} +export interface FileRouteTypes { + fileRoutesByFullPath: FileRoutesByFullPath + fullPaths: '/' + fileRoutesByTo: FileRoutesByTo + to: '/' + id: '__root__' | '/' + fileRoutesById: FileRoutesById +} +export interface RootRouteChildren { + IndexRoute: typeof IndexRoute +} + +declare module '@tanstack/solid-router' { + interface FileRoutesByPath { + '/': { + id: '/' + path: '/' + fullPath: '/' + preLoaderRoute: typeof IndexRouteImport + parentRoute: typeof rootRouteImport + } + } +} + +const rootRouteChildren: RootRouteChildren = { + IndexRoute: IndexRoute, +} +export const routeTree = rootRouteImport + ._addFileChildren(rootRouteChildren) + ._addFileTypes() + +import type { getRouter } from './router.tsx' +import type { createStart } from '@tanstack/solid-start' +declare module '@tanstack/solid-start' { + interface Register { + ssr: true + router: Awaited> + } +} diff --git a/e2e/solid-start/csp/src/router.tsx b/e2e/solid-start/csp/src/router.tsx new file mode 100644 index 0000000000..bf0b283bb6 --- /dev/null +++ b/e2e/solid-start/csp/src/router.tsx @@ -0,0 +1,20 @@ +import { createRouter } from '@tanstack/solid-router' +import { createIsomorphicFn } from '@tanstack/solid-start' +import { routeTree } from './routeTree.gen' + +const getSSROptions = createIsomorphicFn().server(() => { + const array = new Uint8Array(16) + crypto.getRandomValues(array) + const nonce = Array.from(array, (b) => b.toString(16).padStart(2, '0')).join( + '', + ) + return { nonce } +}) + +export function getRouter() { + return createRouter({ + routeTree, + scrollRestoration: true, + ssr: getSSROptions(), + }) +} diff --git a/e2e/solid-start/csp/src/routes/__root.tsx b/e2e/solid-start/csp/src/routes/__root.tsx new file mode 100644 index 0000000000..82faa1929d --- /dev/null +++ b/e2e/solid-start/csp/src/routes/__root.tsx @@ -0,0 +1,49 @@ +import { + createRootRoute, + HeadContent, + Outlet, + Scripts, +} from '@tanstack/solid-router' +import { HydrationScript } from 'solid-js/web' + +export const Route = createRootRoute({ + headers: ({ ssr }) => { + const nonce = ssr?.nonce + if (!nonce) return + return { + 'Content-Security-Policy': [ + "default-src 'self'", + `script-src 'self' 'nonce-${nonce}'`, + `style-src 'self' 'nonce-${nonce}'`, + ].join('; '), + } + }, + head: () => ({ + meta: [ + { charSet: 'utf-8' }, + { name: 'viewport', content: 'width=device-width, initial-scale=1' }, + { title: 'CSP Nonce Test' }, + ], + links: [{ rel: 'stylesheet', href: '/external.css' }], + scripts: [{ src: '/external.js' }], + styles: [ + { children: '.inline-styled { color: green; font-weight: bold; }' }, + ], + }), + component: RootComponent, +}) + +function RootComponent() { + return ( + + + + + + + + + + + ) +} diff --git a/e2e/solid-start/csp/src/routes/index.tsx b/e2e/solid-start/csp/src/routes/index.tsx new file mode 100644 index 0000000000..d737e5d477 --- /dev/null +++ b/e2e/solid-start/csp/src/routes/index.tsx @@ -0,0 +1,25 @@ +import { createSignal } from 'solid-js' +import { createFileRoute } from '@tanstack/solid-router' + +export const Route = createFileRoute('/')({ + component: Home, +}) + +function Home() { + const [count, setCount] = createSignal(0) + + return ( +
+

CSP Nonce Test

+

+ This should be green if inline styles work +

+

+ This should be blue if external styles work +

+ +
+ ) +} diff --git a/e2e/solid-start/csp/tests/csp.spec.ts b/e2e/solid-start/csp/tests/csp.spec.ts new file mode 100644 index 0000000000..247f3b5965 --- /dev/null +++ b/e2e/solid-start/csp/tests/csp.spec.ts @@ -0,0 +1,170 @@ +import { expect } from '@playwright/test' +import { test } from '@tanstack/router-e2e-utils' + +test('CSP header is set with nonce', async ({ page }) => { + const response = await page.goto('/') + const csp = response?.headers()['content-security-policy'] + expect(csp).toContain("script-src 'self' 'nonce-") + expect(csp).toContain("style-src 'self' 'nonce-") +}) + +test('Inline scripts have nonce attribute', async ({ page }) => { + await page.goto('/') + const scripts = await page.locator('script[nonce]').all() + expect(scripts.length).toBeGreaterThan(0) +}) + +test('Inline styles have nonce attribute', async ({ page }) => { + await page.goto('/') + const styles = await page.locator('style[nonce]').all() + expect(styles.length).toBeGreaterThan(0) +}) + +test('External script has nonce attribute', async ({ page }) => { + await page.goto('/') + const externalScript = page.locator('script[src="/external.js"]') + await expect(externalScript).toHaveAttribute('nonce') +}) + +test('External stylesheet has nonce attribute', async ({ page }) => { + await page.goto('/') + const externalStylesheet = page.locator('link[href="/external.css"]') + await expect(externalStylesheet).toHaveAttribute('nonce') +}) + +test('Nonces match between header and elements', async ({ page }) => { + // Intercept the HTML response to get raw content before browser strips nonces + let rawHtml = '' + await page.route('/', async (route) => { + const response = await route.fetch() + rawHtml = await response.text() + await route.fulfill({ response }) + }) + + const response = await page.goto('/') + await page.unrouteAll({ behavior: 'ignoreErrors' }) + + const csp = response?.headers()['content-security-policy'] || '' + + // Extract nonce from CSP header + const nonceMatch = csp.match(/nonce-([a-f0-9]+)/) + expect(nonceMatch).toBeTruthy() + const headerNonce = nonceMatch![1] + + // Check script nonces match - look for nonce attribute anywhere in the script tag + const scriptNonces = [ + ...rawHtml.matchAll(/]*\bnonce="([^"]+)"[^>]*>/g), + ].map((m) => m[1]) + expect(scriptNonces.length).toBeGreaterThan(0) + for (const nonce of scriptNonces) { + expect(nonce).toBe(headerNonce) + } + + // Check style nonces match + const styleNonces = [ + ...rawHtml.matchAll(/]*\bnonce="([^"]+)"[^>]*>/g), + ].map((m) => m[1]) + expect(styleNonces.length).toBeGreaterThan(0) + for (const nonce of styleNonces) { + expect(nonce).toBe(headerNonce) + } + + // Check external script nonce matches (nonce can be before or after src) + const externalScriptMatch = rawHtml.match( + /]*\bsrc="\/external\.js"[^>]*\bnonce="([^"]+)"[^>]*>|]*\bnonce="([^"]+)"[^>]*\bsrc="\/external\.js"[^>]*>/, + ) + expect(externalScriptMatch).toBeTruthy() + expect(externalScriptMatch![1] || externalScriptMatch![2]).toBe(headerNonce) + + // Check external stylesheet nonce matches (nonce can be before or after href) + const externalStyleMatch = rawHtml.match( + /]*\bhref="\/external\.css"[^>]*\bnonce="([^"]+)"[^>]*>|]*\bnonce="([^"]+)"[^>]*\bhref="\/external\.css"[^>]*>/, + ) + expect(externalStyleMatch).toBeTruthy() + expect(externalStyleMatch![1] || externalStyleMatch![2]).toBe(headerNonce) +}) + +test('Hydration works - counter increments', async ({ page }) => { + await page.goto('/') + await expect(page.getByTestId('counter-value')).toContainText('0') + + // Keep clicking until Solid hydrates and the counter increments + // This handles the race between test execution and hydration + await expect + .poll( + async () => { + await page.getByTestId('counter-btn').click() + return page.getByTestId('counter-value').textContent() + }, + { timeout: 10000, intervals: [100, 200, 500, 1000] }, + ) + .not.toBe('0') + + // Now that hydration is confirmed, verify further increments work + const currentValue = parseInt( + (await page.getByTestId('counter-value').textContent()) || '0', + ) + await page.getByTestId('counter-btn').click() + await expect(page.getByTestId('counter-value')).toContainText( + String(currentValue + 1), + ) +}) + +test('Inline styles work with CSP', async ({ page }) => { + await page.goto('/') + const el = page.getByTestId('inline-styled') + await expect(el).toBeVisible() + // Verify the style was applied (green color) + const color = await el.evaluate((e) => getComputedStyle(e).color) + expect(color).toBe('rgb(0, 128, 0)') // green +}) + +test('External styles work with CSP', async ({ page }) => { + await page.goto('/') + const el = page.getByTestId('external-styled') + await expect(el).toBeVisible() + // Verify the style was applied (blue color) + const color = await el.evaluate((e) => getComputedStyle(e).color) + expect(color).toBe('rgb(0, 0, 255)') // blue +}) + +test('External script executes with CSP', async ({ page }) => { + await page.goto('/') + // Check that the external script set its window global + await expect + .poll(() => page.evaluate(() => (window as any).__EXTERNAL_SCRIPT_LOADED__)) + .toBe(true) +}) + +test('No CSP violations in console', async ({ page }) => { + const violations: string[] = [] + page.on('console', (msg) => { + if (msg.text().toLowerCase().includes('content security policy')) { + violations.push(msg.text()) + } + }) + page.on('pageerror', (err) => { + if (err.message.toLowerCase().includes('content security policy')) { + violations.push(err.message) + } + }) + await page.goto('/') + await page.getByTestId('counter-btn').click() + // Small wait to ensure any async violations are caught + await page.waitForTimeout(100) + expect(violations).toEqual([]) +}) + +test('Each request gets a unique nonce', async ({ page }) => { + const response1 = await page.goto('/') + const csp1 = response1?.headers()['content-security-policy'] || '' + const nonce1 = csp1.match(/nonce-([a-f0-9]+)/)?.[1] + + const response2 = await page.goto('/') + const csp2 = response2?.headers()['content-security-policy'] || '' + const nonce2 = csp2.match(/nonce-([a-f0-9]+)/)?.[1] + + expect(nonce1).toBeTruthy() + expect(nonce2).toBeTruthy() + expect(nonce1).not.toBe(nonce2) +}) diff --git a/e2e/solid-start/csp/tsconfig.json b/e2e/solid-start/csp/tsconfig.json new file mode 100644 index 0000000000..a40235b863 --- /dev/null +++ b/e2e/solid-start/csp/tsconfig.json @@ -0,0 +1,23 @@ +{ + "include": ["**/*.ts", "**/*.tsx"], + "compilerOptions": { + "strict": true, + "esModuleInterop": true, + "jsx": "preserve", + "jsxImportSource": "solid-js", + "module": "ESNext", + "moduleResolution": "Bundler", + "lib": ["DOM", "DOM.Iterable", "ES2022"], + "isolatedModules": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "target": "ES2022", + "allowJs": true, + "forceConsistentCasingInFileNames": true, + "baseUrl": ".", + "paths": { + "~/*": ["./src/*"] + }, + "noEmit": true + } +} diff --git a/e2e/solid-start/csp/vite.config.ts b/e2e/solid-start/csp/vite.config.ts new file mode 100644 index 0000000000..a9913da087 --- /dev/null +++ b/e2e/solid-start/csp/vite.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from 'vite' +import { tanstackStart } from '@tanstack/solid-start/plugin/vite' +import viteSolid from 'vite-plugin-solid' + +export default defineConfig({ + server: { + port: 3000, + }, + plugins: [tanstackStart(), viteSolid({ ssr: true })], +}) diff --git a/e2e/vue-start/csp/.gitignore b/e2e/vue-start/csp/.gitignore new file mode 100644 index 0000000000..a86a144649 --- /dev/null +++ b/e2e/vue-start/csp/.gitignore @@ -0,0 +1,5 @@ +node_modules +dist +.output +test-results +playwright-report diff --git a/e2e/vue-start/csp/package.json b/e2e/vue-start/csp/package.json new file mode 100644 index 0000000000..4b42ca2e25 --- /dev/null +++ b/e2e/vue-start/csp/package.json @@ -0,0 +1,28 @@ +{ + "name": "tanstack-vue-start-e2e-csp", + "private": true, + "sideEffects": false, + "type": "module", + "scripts": { + "dev": "vite dev --port 3000", + "dev:e2e": "vite dev", + "build": "vite build && tsc --noEmit", + "start": "pnpx srvx --prod -s ../client dist/server/server.js", + "test:e2e": "rm -rf port*.txt; playwright test --project=chromium" + }, + "dependencies": { + "@tanstack/vue-router": "workspace:^", + "@tanstack/vue-start": "workspace:^", + "vue": "^3.5.16", + "vite": "^7.1.7" + }, + "devDependencies": { + "@playwright/test": "^1.50.1", + "@tanstack/router-e2e-utils": "workspace:^", + "@types/node": "^22.10.2", + "@vitejs/plugin-vue": "^5.2.4", + "@vitejs/plugin-vue-jsx": "^4.1.2", + "srvx": "^0.10.0", + "typescript": "^5.7.2" + } +} diff --git a/e2e/vue-start/csp/playwright.config.ts b/e2e/vue-start/csp/playwright.config.ts new file mode 100644 index 0000000000..5f9de5709e --- /dev/null +++ b/e2e/vue-start/csp/playwright.config.ts @@ -0,0 +1,35 @@ +import { defineConfig, devices } from '@playwright/test' +import { getTestServerPort } from '@tanstack/router-e2e-utils' +import packageJson from './package.json' with { type: 'json' } + +const PORT = await getTestServerPort(packageJson.name) +const baseURL = `http://localhost:${PORT}` + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + testDir: './tests', + workers: 1, + + reporter: [['line']], + + use: { + /* Base URL to use in actions like `await page.goto('/')`. */ + baseURL, + }, + + webServer: { + command: `VITE_SERVER_PORT=${PORT} pnpm build && PORT=${PORT} VITE_SERVER_PORT=${PORT} pnpm start`, + url: baseURL, + reuseExistingServer: !process.env.CI, + stdout: 'pipe', + }, + + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + ], +}) diff --git a/e2e/vue-start/csp/public/external.css b/e2e/vue-start/csp/public/external.css new file mode 100644 index 0000000000..4085d14afd --- /dev/null +++ b/e2e/vue-start/csp/public/external.css @@ -0,0 +1,4 @@ +.external-styled { + color: blue; + font-weight: bold; +} diff --git a/e2e/vue-start/csp/public/external.js b/e2e/vue-start/csp/public/external.js new file mode 100644 index 0000000000..1909a765be --- /dev/null +++ b/e2e/vue-start/csp/public/external.js @@ -0,0 +1,3 @@ +// This script sets a window global when loaded +// Using a global avoids race conditions with Vue and DOM ownership issues +window.__EXTERNAL_SCRIPT_LOADED__ = true diff --git a/e2e/vue-start/csp/src/routeTree.gen.ts b/e2e/vue-start/csp/src/routeTree.gen.ts new file mode 100644 index 0000000000..7a8d4c0038 --- /dev/null +++ b/e2e/vue-start/csp/src/routeTree.gen.ts @@ -0,0 +1,68 @@ +/* eslint-disable */ + +// @ts-nocheck + +// noinspection JSUnusedGlobalSymbols + +// This file was automatically generated by TanStack Router. +// You should NOT make any changes in this file as it will be overwritten. +// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. + +import { Route as rootRouteImport } from './routes/__root' +import { Route as IndexRouteImport } from './routes/index' + +const IndexRoute = IndexRouteImport.update({ + id: '/', + path: '/', + getParentRoute: () => rootRouteImport, +} as any) + +export interface FileRoutesByFullPath { + '/': typeof IndexRoute +} +export interface FileRoutesByTo { + '/': typeof IndexRoute +} +export interface FileRoutesById { + __root__: typeof rootRouteImport + '/': typeof IndexRoute +} +export interface FileRouteTypes { + fileRoutesByFullPath: FileRoutesByFullPath + fullPaths: '/' + fileRoutesByTo: FileRoutesByTo + to: '/' + id: '__root__' | '/' + fileRoutesById: FileRoutesById +} +export interface RootRouteChildren { + IndexRoute: typeof IndexRoute +} + +declare module '@tanstack/vue-router' { + interface FileRoutesByPath { + '/': { + id: '/' + path: '/' + fullPath: '/' + preLoaderRoute: typeof IndexRouteImport + parentRoute: typeof rootRouteImport + } + } +} + +const rootRouteChildren: RootRouteChildren = { + IndexRoute: IndexRoute, +} +export const routeTree = rootRouteImport + ._addFileChildren(rootRouteChildren) + ._addFileTypes() + +import type { getRouter } from './router.tsx' +import type { createStart } from '@tanstack/vue-start' +declare module '@tanstack/vue-start' { + interface Register { + ssr: true + router: Awaited> + } +} diff --git a/e2e/vue-start/csp/src/router.tsx b/e2e/vue-start/csp/src/router.tsx new file mode 100644 index 0000000000..a5ee379d73 --- /dev/null +++ b/e2e/vue-start/csp/src/router.tsx @@ -0,0 +1,20 @@ +import { createRouter } from '@tanstack/vue-router' +import { createIsomorphicFn } from '@tanstack/vue-start' +import { routeTree } from './routeTree.gen' + +const getSSROptions = createIsomorphicFn().server(() => { + const array = new Uint8Array(16) + crypto.getRandomValues(array) + const nonce = Array.from(array, (b) => b.toString(16).padStart(2, '0')).join( + '', + ) + return { nonce } +}) + +export function getRouter() { + return createRouter({ + routeTree, + scrollRestoration: true, + ssr: getSSROptions(), + }) +} diff --git a/e2e/vue-start/csp/src/routes/__root.tsx b/e2e/vue-start/csp/src/routes/__root.tsx new file mode 100644 index 0000000000..99447679c7 --- /dev/null +++ b/e2e/vue-start/csp/src/routes/__root.tsx @@ -0,0 +1,49 @@ +import { + Body, + createRootRoute, + HeadContent, + Html, + Outlet, + Scripts, +} from '@tanstack/vue-router' + +export const Route = createRootRoute({ + headers: ({ ssr }) => { + const nonce = ssr?.nonce + if (!nonce) return + return { + 'Content-Security-Policy': [ + "default-src 'self'", + `script-src 'self' 'nonce-${nonce}'`, + `style-src 'self' 'nonce-${nonce}'`, + ].join('; '), + } + }, + head: () => ({ + meta: [ + { charSet: 'utf-8' }, + { name: 'viewport', content: 'width=device-width, initial-scale=1' }, + { title: 'CSP Nonce Test' }, + ], + links: [{ rel: 'stylesheet', href: '/external.css' }], + scripts: [{ src: '/external.js' }], + styles: [ + { children: '.inline-styled { color: green; font-weight: bold; }' }, + ], + }), + component: RootComponent, +}) + +function RootComponent() { + return ( + + + + + + + + + + ) +} diff --git a/e2e/vue-start/csp/src/routes/index.tsx b/e2e/vue-start/csp/src/routes/index.tsx new file mode 100644 index 0000000000..63cb71c1e5 --- /dev/null +++ b/e2e/vue-start/csp/src/routes/index.tsx @@ -0,0 +1,25 @@ +import { ref } from 'vue' +import { createFileRoute } from '@tanstack/vue-router' + +export const Route = createFileRoute('/')({ + component: Home, +}) + +function Home() { + const count = ref(0) + + return ( +
+

CSP Nonce Test

+

+ This should be green if inline styles work +

+

+ This should be blue if external styles work +

+ +
+ ) +} diff --git a/e2e/vue-start/csp/tests/csp.spec.ts b/e2e/vue-start/csp/tests/csp.spec.ts new file mode 100644 index 0000000000..9456642460 --- /dev/null +++ b/e2e/vue-start/csp/tests/csp.spec.ts @@ -0,0 +1,394 @@ +import { expect } from '@playwright/test' +import { test } from '@tanstack/router-e2e-utils' + +test('CSP header is set with nonce', async ({ page }) => { + const response = await page.goto('/') + const csp = response?.headers()['content-security-policy'] + expect(csp).toContain("script-src 'self' 'nonce-") + expect(csp).toContain("style-src 'self' 'nonce-") +}) + +test('Inline scripts have nonce attribute', async ({ page }) => { + await page.goto('/') + const scripts = await page.locator('script[nonce]').all() + expect(scripts.length).toBeGreaterThan(0) +}) + +test('Inline styles have nonce attribute', async ({ page }) => { + await page.goto('/') + const styles = await page.locator('style[nonce]').all() + expect(styles.length).toBeGreaterThan(0) +}) + +test('External script has nonce attribute', async ({ page }) => { + await page.goto('/') + const externalScript = page.locator('script[src="/external.js"]') + await expect(externalScript).toHaveAttribute('nonce') +}) + +test('External stylesheet has nonce attribute', async ({ page }) => { + await page.goto('/') + const externalStylesheet = page.locator('link[href="/external.css"]') + await expect(externalStylesheet).toHaveAttribute('nonce') +}) + +test('Nonces match between header and elements', async ({ page }) => { + // Intercept the HTML response to get raw content before browser strips nonces + let rawHtml = '' + await page.route('/', async (route) => { + const response = await route.fetch() + rawHtml = await response.text() + await route.fulfill({ response }) + }) + + const response = await page.goto('/') + await page.unrouteAll({ behavior: 'ignoreErrors' }) + + const csp = response?.headers()['content-security-policy'] || '' + + // Extract nonce from CSP header + const nonceMatch = csp.match(/nonce-([a-f0-9]+)/) + expect(nonceMatch).toBeTruthy() + const headerNonce = nonceMatch![1] + + // Check script nonces match - look for nonce attribute anywhere in the script tag + const scriptNonces = [ + ...rawHtml.matchAll(/]*\bnonce="([^"]+)"[^>]*>/g), + ].map((m) => m[1]) + expect(scriptNonces.length).toBeGreaterThan(0) + for (const nonce of scriptNonces) { + expect(nonce).toBe(headerNonce) + } + + // Check style nonces match + const styleNonces = [ + ...rawHtml.matchAll(/]*\bnonce="([^"]+)"[^>]*>/g), + ].map((m) => m[1]) + expect(styleNonces.length).toBeGreaterThan(0) + for (const nonce of styleNonces) { + expect(nonce).toBe(headerNonce) + } + + // Check external script nonce matches (nonce can be before or after src) + const externalScriptMatch = rawHtml.match( + /]*\bsrc="\/external\.js"[^>]*\bnonce="([^"]+)"[^>]*>|]*\bnonce="([^"]+)"[^>]*\bsrc="\/external\.js"[^>]*>/, + ) + expect(externalScriptMatch).toBeTruthy() + expect(externalScriptMatch![1] || externalScriptMatch![2]).toBe(headerNonce) + + // Check external stylesheet nonce matches (nonce can be before or after href) + const externalStyleMatch = rawHtml.match( + /]*\bhref="\/external\.css"[^>]*\bnonce="([^"]+)"[^>]*>|]*\bnonce="([^"]+)"[^>]*\bhref="\/external\.css"[^>]*>/, + ) + expect(externalStyleMatch).toBeTruthy() + expect(externalStyleMatch![1] || externalStyleMatch![2]).toBe(headerNonce) +}) + +test('Hydration works - counter increments', async ({ page }) => { + const cspViolations: any[] = [] + // page.on handlers must be registered before navigation + page.on('console', (msg) => { + if (msg.text().toLowerCase().includes('content security policy')) { + cspViolations.push({ + type: msg.type(), + text: msg.text(), + location: msg.location?.(), + }) + } + }) + + // Capture raw SSR HTML (includes nonces) and CSP header + let rawHtml = '' + let cspHeader = '' + await page.route('/', async (route) => { + const response = await route.fetch() + cspHeader = response.headers()['content-security-policy'] || '' + rawHtml = await response.text() + await route.fulfill({ response }) + }) + + await page.addInitScript(() => { + const record = (window as any).__CSP_STYLE_MUTATIONS__ + ? (window as any).__CSP_STYLE_MUTATIONS__ + : ((window as any).__CSP_STYLE_MUTATIONS__ = []) + + window.addEventListener( + 'securitypolicyviolation', + (e) => { + record.push({ + kind: 'securitypolicyviolation', + blockedURI: e.blockedURI, + effectiveDirective: e.effectiveDirective, + violatedDirective: e.violatedDirective, + originalPolicy: e.originalPolicy, + sample: e.sample, + disposition: e.disposition, + documentURI: e.documentURI, + lineNumber: e.lineNumber, + columnNumber: e.columnNumber, + sourceFile: e.sourceFile, + statusCode: e.statusCode, + }) + }, + true, + ) + + const originalSetAttribute = Element.prototype.setAttribute + Element.prototype.setAttribute = function (name: string, value: string) { + if (name === 'style') { + record.push({ + kind: 'setAttribute', + tagName: (this as any).tagName, + id: (this as any).id, + className: (this as any).className, + testId: (this as any).getAttribute?.('data-testid'), + value, + stack: new Error('setAttribute style').stack, + }) + } + return originalSetAttribute.call(this, name, value) + } + + const originalCssText = Object.getOwnPropertyDescriptor( + CSSStyleDeclaration.prototype, + 'cssText', + ) + if (originalCssText?.set) { + Object.defineProperty(CSSStyleDeclaration.prototype, 'cssText', { + get: originalCssText.get, + set(value) { + record.push({ + kind: 'cssText', + value, + stack: new Error('cssText set').stack, + }) + return originalCssText.set!.call(this, value) + }, + }) + } + + const originalSetProperty = CSSStyleDeclaration.prototype.setProperty + CSSStyleDeclaration.prototype.setProperty = function (...args) { + record.push({ + kind: 'setProperty', + args, + stack: new Error('setProperty').stack, + }) + return originalSetProperty.apply(this, args as any) + } + + const originalInsertRule = CSSStyleSheet.prototype.insertRule + CSSStyleSheet.prototype.insertRule = function (...args) { + record.push({ + kind: 'insertRule', + args, + stack: new Error('insertRule').stack, + }) + return originalInsertRule.apply(this, args as any) + } + + const originalCreateElement = Document.prototype.createElement + Document.prototype.createElement = function (...args: any[]) { + const el = originalCreateElement.apply(this, args as any) + if (String(args[0]).toLowerCase() === 'style') { + record.push({ + kind: 'createStyle', + nonce: + (el as any).nonce ?? (el as any).getAttribute?.('nonce') ?? null, + stack: new Error('create style').stack, + }) + + const originalTextContent = Object.getOwnPropertyDescriptor( + Node.prototype, + 'textContent', + ) + const originalSetTextContent = originalTextContent?.set + + if (originalSetTextContent) { + try { + Object.defineProperty(el, 'textContent', { + get: originalTextContent!.get, + set(value) { + record.push({ + kind: 'styleTextContent', + value, + stack: new Error('style textContent').stack, + }) + return originalSetTextContent.call(this, value) + }, + }) + } catch { + // ignore if non-configurable + } + } + } + return el + } + + const originalAppendChild = Node.prototype.appendChild + Node.prototype.appendChild = function (child: any) { + if (child?.tagName === 'STYLE' || child?.nodeName === 'STYLE') { + record.push({ + kind: 'appendStyle', + nonce: (child as any).nonce ?? child.getAttribute?.('nonce') ?? null, + text: child.textContent, + stack: new Error('append style').stack, + }) + } + return originalAppendChild.call(this, child) as any + } + + const originalInsertBefore = Node.prototype.insertBefore + Node.prototype.insertBefore = function (newNode: any, referenceNode: any) { + if (newNode?.tagName === 'STYLE' || newNode?.nodeName === 'STYLE') { + record.push({ + kind: 'insertBeforeStyle', + text: newNode.textContent, + stack: new Error('insertBefore style').stack, + }) + } + return originalInsertBefore.call(this, newNode, referenceNode) as any + } + }) + + const response = await page.goto('/') + await page.unrouteAll({ behavior: 'ignoreErrors' }) + + // Sanity check: SSR should already include the route-head inline style tag with a nonce. + // If this is present, Vue should not need to re-insert a case 'script': return default: diff --git a/packages/vue-router/src/Asset.tsx b/packages/vue-router/src/Asset.tsx index cf66889d17..dbc753023f 100644 --- a/packages/vue-router/src/Asset.tsx +++ b/packages/vue-router/src/Asset.tsx @@ -155,18 +155,32 @@ const Script = Vue.defineComponent({ }, }) -export function Asset({ tag, attrs, children }: RouterManagedTag): any { +export function Asset({ + tag, + attrs, + children, + nonce, +}: RouterManagedTag & { nonce?: string }): any { + const nonceAttr = nonce ? { nonce } : {} switch (tag) { case 'title': return Vue.h(Title, { children: children }) case 'meta': - return + return Vue.h('meta', attrs) case 'link': - return + return Vue.h('link', { ...attrs, ...nonceAttr }) case 'style': - return