Replies: 4 comments
-
good idea |
Beta Was this translation helpful? Give feedback.
-
Subscribed! Our team is also having a massive pain with this. On doing some browsing around there seem to be some solutions to this but a lot of them seem outdated and / or quite hacky making them unideal. @danieltott from your issue I found here |
Beta Was this translation helpful? Give feedback.
-
You currently can use a good, non- When the Next.js renderer renders a page with a This can be done via middleware - see here for source, and here for a working example. I would love to see a better solution for this though. Currently you need to add custom code to middleware, and, as stated above, this only works for dynamic pages.
|
Beta Was this translation helpful? Give feedback.
-
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 🙏 I'll be closing this discussion out. To continue the discussion, please go here. |
Beta Was this translation helpful? Give feedback.
-
Goals
Be able to set a
script-src
Content Security Policy that does not includeunsafe-inline
.Background
The docs provide an example Content Security Policy that sets
script-src
to'self'
. Unfortunately, when using Server Components (at least, I think those are the trigger, but it might be related to the app router or server-side rendering), Next.js appends a bunch of<script>
tags to the DOM, presumably to stream the client components to the page?Also note that MDN says:
Proposal
I think there are a couple of options ways to support streaming rendering without adding
'unsafe-inline'
:Beta Was this translation helpful? Give feedback.
All reactions