fix: nonce support #5287
Merged
schiller-manuel(GitHub profile, opens in a new tab)merged 1 commit into
main fromrefs/pull/5287/head·merged by schiller-manuel(GitHub profile, opens in a new tab) Summary by CodeRabbit#
- New Features
- Added optional nonce support to assets, enabling nonce attributes on rendered scripts, styles, and links.
- Automatically propagates a configured nonce from router SSR options to all head assets and scripts.
- Server-side rendering for both React and Solid now forwards the nonce to ensure consistent nonce application in streamed and string-rendered output.
- Improves compatibility with strict Content Security Policies by reducing manual nonce wiring.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-router
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-router
View your CI Pipeline Execution ↗ for commit cb01ecdf75d3ed70c0825a7a0e8c128b1e7f0652
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 7m 42s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1m 6s View ↗
☁️ Nx Cloud last updated this comment at
2025-09-28 23:17:35UTCMore templates
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-solid-start-example-bare
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-static
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
@tanstack/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5287@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5287@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5287@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5287@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5287@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5287@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5287@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5287@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5287@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5287@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5287@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5287@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5287@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5287@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5287@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5287@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5287@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5287@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5287@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5287@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5287@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5287@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5287@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5287@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5287@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5287@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5287@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5287@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5287@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5287@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5287@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5287@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5287@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5287commit:
cb01ecd
Sign in to join this conversation.
Walkthrough#
Adds optional nonce support across React and Solid router rendering paths. Propagates router.options.ssr?.nonce into SSR render options and through HeadContent/Scripts into Asset and Script elements, applying nonce to link, style, and script tags. Public Asset signature updated to accept nonce.
Changes#
packages/react-router/src/Asset.tsxRouterManagedTag & { nonce?: string }. Passes nonce to rendered link/style elements and to Script (including inline and src cases). Internal Script updated to accept and apply nonce.packages/react-router/src/HeadContent.tsx,packages/react-router/src/Scripts.tsxrouter.options.ssr?.nonceand forwards it asnonceto each Asset render, affecting all head and script assets.packages/react-router/src/ssr/renderRouterToStream.tsxnonce: router.options.ssr?.nonceto ReactDOMServer render options for both Readable and Pipeable streams.packages/solid-router/src/ssr/renderRouterToStream.tsx,packages/solid-router/src/ssr/renderRouterToString.tsxnonce: router.options.ssr?.nonceto Solid’srenderToStreamandrenderToStringoptions; no other flow changes.Sequence Diagram(s)#
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs#
Poem#
Pre-merge checks and finishing touches#
❌ Failed checks (1 warning)
@coderabbitai generate docstringsto improve docstring coverage.✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 7a129f7f0b1d5c3c45065ad4e2ac3fca5ceb5295 and cb01ecdf75d3ed70c0825a7a0e8c128b1e7f0652.
📒 Files selected for processing (6)
packages/react-router/src/Asset.tsx(5 hunks)packages/react-router/src/HeadContent.tsx(1 hunks)packages/react-router/src/Scripts.tsx(1 hunks)packages/react-router/src/ssr/renderRouterToStream.tsx(2 hunks)packages/solid-router/src/ssr/renderRouterToStream.tsx(1 hunks)packages/solid-router/src/ssr/renderRouterToString.tsx(1 hunks)🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/solid-router/src/ssr/renderRouterToString.tsxpackages/react-router/src/ssr/renderRouterToStream.tsxpackages/react-router/src/HeadContent.tsxpackages/solid-router/src/ssr/renderRouterToStream.tsxpackages/react-router/src/Asset.tsxpackages/react-router/src/Scripts.tsxpackages/{react-router,solid-router}/**
📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/solid-router/src/ssr/renderRouterToString.tsxpackages/react-router/src/ssr/renderRouterToStream.tsxpackages/react-router/src/HeadContent.tsxpackages/solid-router/src/ssr/renderRouterToStream.tsxpackages/react-router/src/Asset.tsxpackages/react-router/src/Scripts.tsx🧠 Learnings (1)
📚 Learning: 2025-09-23T17:36:12.598Z
Applied to files:
packages/solid-router/src/ssr/renderRouterToString.tsx🧬 Code graph analysis (2)
packages/react-router/src/HeadContent.tsx (1)
packages/react-router/src/Scripts.tsx (1)
🪛 ast-grep (0.39.5)
packages/react-router/src/Asset.tsx
[warning] 31-31: Usage of dangerouslySetInnerHTML detected. This bypasses React's built-in XSS protection. Always sanitize HTML content using libraries like DOMPurify before injecting it into the DOM to prevent XSS attacks. Context: dangerouslySetInnerHTML Note: [CWE-79] Improper Neutralization of Input During Web Page Generation [REFERENCES]
(react-unsafe-html-injection)
🪛 Biome (2.1.2)
packages/react-router/src/Asset.tsx
[error] 32-32: Avoid passing content using the dangerouslySetInnerHTML prop.
Setting content using code can expose users to cross-site scripting (XSS) attacks
(lint/security/noDangerouslySetInnerHtml)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (5)
Comment `@coderabbitai help` to get the list of available commands and usage tips.