You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inline scripts are duplicated after hydration when the CSP nonce is sent in a header #8550
When the CSP arrives in a response header, browsers apply nonce hiding. On a connected element, getAttribute('nonce') returns '', and only the .nonce property keeps the value. So the comparison is '' vs. the real nonce, and the server-rendered script never matches. Script then creates a new <script type="module" nonce>import("/assets/index-….js")</script>, sets its textContent, and appends it to <head>.
Set ssr.nonce on the router and send Content-Security-Policy: script-src 'nonce-<n>' as a response header.
Load a page. document.head.querySelectorAll('script[type=module]') includes a re-added import("/assets/…") script. Its getAttribute('nonce') is '', and its .nonce has the value.
Control: send the same policy in a <meta http-equiv>, or send no policy. Nonces aren't hidden, the lookup matches, and nothing is added.
Add ; require-trusted-types-for 'script' to the header. Hydration fails with the error above.
I tested this using react-router, but the issue is likely the same in solid and vue
Expected behavior
The lookup matches the server-rendered script, and nothing is created or appended.
The fix uses || rather than ?? because .nonce is '' when an element has no nonce. With ??, apps that don't use a nonce would start creating duplicates.
Screenshots or Videos
No response
Platform
Router / Start Version: 1.170.40
OS: macOS
Browser: Tested in chrome, safari and firefox
Browser Version: Safari Version 27.2 (22625.2.5.11.1)
Activity
✨ feat(tanstack): opt-in security headers; token checker counts break…
feat(web): send security headers on every response