-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSP Nonce attribute not added to all script tags #4591
Comments
(example posted didn't have |
Hey there is a PR to fix this here #4539 |
This issue should be closed |
Hey folks, wanted to swing back here with an update. After digging through many different issues and discussions, I've made a new page in the documentation (PR) specifically for Content Security Policy and nonces. This docs page:
Further, we've patched some bugs and made improvements to Really hope this helps out, thank you all 🙏 To continue the discussion, please go here. |
Bug report
Describe the bug
As far as I can tell, Next.js doesn't support
'strict-dynamic'
+ a nonce as a CSP policy. The nonce is added to one of the script tags here:https://github.com/zeit/next.js/blob/e2beadd9601f3393254eae3f9c5a30abfd4ae988/server/document.js#L182
but for some reason, the nonce is not added to other script tags:
https://github.com/zeit/next.js/blob/e2beadd9601f3393254eae3f9c5a30abfd4ae988/server/document.js#L207-L209
https://github.com/zeit/next.js/blob/e2beadd9601f3393254eae3f9c5a30abfd4ae988/server/document.js#L136-L140
https://github.com/zeit/next.js/blob/e2beadd9601f3393254eae3f9c5a30abfd4ae988/server/document.js#L164-L168
To Reproduce
(Tested in Chrome 66.0.3359.181)
Add CSP policy to
pages/_document.tsx
head:And set
nonce
onNextScript
:Chrome refuses to load the scripts:
Expected behavior
The app to load as usual.
Additional context
I didn't have time to manually setup a fork to create an example repo, but when I added the nonce into the script tags by editing
dist/server/document.js
directly,strict-dynamic
worked as expected.The text was updated successfully, but these errors were encountered: