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
I read your blog post about strict CSP with Next, got curious, and tried it out on my latest project with Next.js 12
Unfortunately, your package didn't work. I was not able to import it from NPM, which gave an error, but I am using yarn berry with zero installs, so I think that's due to that. (for this to work you had to import { Head } from 'next/document' and set next up as a peer dep)
Edit: In the meantime, I released a package @next-safe/middleware (Repo: https://github.com/nibtime/next-safe-middleware) that offers strict CSP support for Next 12 hybrid apps (getStaticProps - Hash-based, getServerSideProps - Nonce-based) via middleware, all by HTTP response header. That is a little bit safer, but most importantly enables reporting, for which the package also provides a convenient setup mechanism. It also works with next/script and hashes/nonces everything behind the scenes and adds stuff to the CSP.
Furthermore, it provides middleware to configure a custom CSP (apart from script-src) on top and to use inline styles without unsafe-inline.
Should anybody have problems with this package or have any of the above requirements, I recommend checking it out (of course I'd say that, I made the package 😁, but I also think it genuinely solves some common CSP issues very well at this point)
The text was updated successfully, but these errors were encountered:
Hi @guydumais
I read your blog post about strict CSP with Next, got curious, and tried it out on my latest project with Next.js 12
Unfortunately, your package didn't work. I was not able to import it from NPM, which gave an error, but I am using yarn berry with zero installs, so I think that's due to that. (for this to work you had to
import { Head } from 'next/document'
and set next up as a peer dep)Edit: In the meantime, I released a package @next-safe/middleware (Repo: https://github.com/nibtime/next-safe-middleware) that offers strict CSP support for Next 12 hybrid apps (getStaticProps - Hash-based, getServerSideProps - Nonce-based) via middleware, all by HTTP response header. That is a little bit safer, but most importantly enables reporting, for which the package also provides a convenient setup mechanism. It also works with
next/script
and hashes/nonces everything behind the scenes and adds stuff to the CSP.Furthermore, it provides middleware to configure a custom CSP (apart from
script-src
) on top and to use inline styles withoutunsafe-inline
.Should anybody have problems with this package or have any of the above requirements, I recommend checking it out (of course I'd say that, I made the package 😁, but I also think it genuinely solves some common CSP issues very well at this point)
The text was updated successfully, but these errors were encountered: