-
Notifications
You must be signed in to change notification settings - Fork 62
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
Nonce doesn't change per request in production build #541
Comments
This is strange But the very strange part is that you said this happens in your local environment build. Not normal at all. |
Hi @vejja, Thanks for the quick response. I just run npm run build. Then preview the build with npx wrangler pages dev dist/ If there is something I can do in Cloudflare to get node:crypto working then that would be great. |
https://developers.cloudflare.com/workers/runtime-apis/nodejs/crypto/ |
No luck unfortunately. I tried both nodejs_compat and nodejs_compat_v2 with a compatibility date of 2024-09-23 or later but the nonce is still the same. |
Locally, what if you |
node .output/server/index.mjs gives output Listening http://[::]:3000 Do I need to configure a host IP somehow? |
Just open Chrome on localhost:3000 |
Yeah I tried that and strangely I'm seeing a really old version of the website that appears to not have nuxt-security at all on http://localhost:3000/. No idea how that can happen. npm run dev / build is showing the latest version which is a relief. |
wow this is becoming really tough to debug 😂
|
nuxt.config.ts
wrangler.toml
Thanks for all the help so far. |
ok, remove |
Yes! That worked. I can see a nonce now. What are the ramifications of removing the nitro preset? Is that required for Cloudflare Pages module "nitro-cloudflare-dev"? |
I'm not 100% sure myself 😉 I'm not a Cloudflare expert, so I don't have a good knowledge of their terminology - but here is the basic stuff you need to know:
I have no first-hand knowledge of how to make this whole stack run on Cloudflare, but my 2 cents are 'cloudflare_pages' probably stands for 'a CDN that can only deliver static files with no runtime' while 'cloudflare_module' probably means 'a full runtime environment that is able to run the Nitro executable'. Now for better advice you should look here and here. |
Thank you for everything you have done so far. Unfortunately, the nonce still didn't work in Cloudflare production but we've clearly made some progress so that's great! I must say, you are an absolute legend @vejja . This is the best support I've received in the last 25 years in IT and it's from an open source project for no $$$. I really appreciate and acknowledge your dedication and perseverance in trying to resolve this for me. I'll look at this again tomorrow with fresh eyes on the last two links you provided. Thanks again! |
Thank you for your kind words @brewaa ! I did have a deeper look in the meantime and I would greatly appreciate if you could try the following:
Would be extremely interested in knowing if it works 🙏🏻 |
Hi @brewaa |
Hi @vejja, Sorry I hadn't got back to this yet. I'll create a new repo to test this now. |
Hi @vejja, I've created a small reproduction repo, tried all of your suggestions and deployed using The new
Unfortunately, not helpful for my situation it seems. |
The nonces are still changing correctly in local dev environment. Do you want access to the repository? |
Yes that would be great |
I’m proposing a change that would supposedly avoid this whole nodejs_compat issue, but some real-life testing would be great. |
@brewaa Thanks for the repo link However I used your repo to test the changes introduced by PR #547 and I can confirm it now works on Cloudflare, the nonce is there as expected. @Baroshem: With this change, Cloudflare users don't need to think about setting a |
Hi @vejja , I'd love to be able to help test, I'm just not sure how I go about it. Is there some way I can use the new branch and somehow get that into my test repo? |
Here is how I did it manually:
I wish there was an easier way to do it... but you can probably use the same procedure on your end. @Baroshem: if you think this would be useful for those of our users who want to test 2.1, I can release an RC version on npm. Let me know |
Sorry @vejja. I'm getting:
What do I need to install? |
did you |
Ahh yes. Thanks. No I didn't yarn first. I've deleted everything and started again.
Receiving error:
I can't see a If this is just me, understandable if this is not worth pursuing, I don't want to take up too much of your time. I'm really happy with the effort you've put in so far and I'd be happy to wait to the 2.1.0 release. Thanks for your help. |
sorry it's me, I think you probably need to |
YES!!! That worked @vejja !! You are the best! I can confirm nonces are working in Cloudflare with chore/2.1.0. |
Awesome, let's plan to release 2.1.0 with this change then! :) Thanks for the amazing work @vejja ! |
@pi0 I'm flagging you here on this thread as I think we might have uncovered an edge case here - we would need your advice. OP is deploying on Cloudflare using preset I looked at the nitro server code generated by I might be completely wrong, but from the surface of it, it looks like an |
Hi,
I've added a CSP but I'm having an issue with nonces not changing for a production deployment.
Running npm run dev the nonce changes per request.
Running npm run build , the nonce doesn't change. It's always this:
This happens in my local environment build and in production build which is Cloudflare Pages.
I tried a couple of versions both having the same result:
nuxt-security: 2.0.0-rc.9
nuxt-security: v2.0.0
nuxt: 3.12.3
The CSP I'm using is the same as listed on the FAQ page for Cloudflare config (https://nuxt-security.vercel.app/documentation/advanced/faq)
Is this a known issue and maybe I've missed a configuration?
The text was updated successfully, but these errors were encountered: