Skip to content

Next.js 15: CSP headers not applied in production unless await headers() is called #80997

Answered by icyJoseph
makboc asked this question in App Router
Discussion options

You must be logged in to vote

HI,

What you need is to make your page dynamic ~ https://nextjs.org/docs/app/guides/content-security-policy#adding-a-nonce-with-middleware

Try with export const dynamic = 'force-dynamic'

Every time a page is viewed, a fresh nonce should be generated. This means that you must use dynamic rendering to add nonces.

I have merged a documentation update pointing to dynamic rendering, but it hasn't deployed to the docs site yet.

Otherwise, a page gets opted-in to static rendering, and then the nonce is not applied to the scripts in the HTML send to the browser, cuz it ws already made during build time.

Also I was testing out with use client components, and found an issue too.

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@makboc
Comment options

Answer selected by makboc
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants