-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Issue setting strict CSP in production #16749
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
@btea I'm not entirely sure I follow and how adding it to the original meta tag would differ from how I am doing it now. Either way, and correct me if I'm wrong, I think the main issue will still remain; after packaging the app the nonce will no longer be regenerated. |
This comment was marked as off-topic.
This comment was marked as off-topic.
@btea My issue isn't getting the nonce to work, I already have that working. My issue is that using a nonce seems to be the only supported way of using a strict Content Security Policy with Vite. This won't work for me because after I package my app with electron, the nonce won't be regenerated anymore. Having a static nonce in my index.html defeats the whole purpose of a nonce. |
Oh, sorry, it seems that I misunderstand what you mean. 🤦♂️ |
No worries! I appreciate you trying to help |
@TylerWanta Hey! I have been working on a vite plugin to solve this specific problem. The issue is the nonce strategy doesn't support SPA's - what we need is hashes. Here is the plugin - its still pre 1.0 but I have written up some extensive documentation for the plugin as well as this specific problem. Try it out and let me know what you think! All feedback is welcome |
Hello @RockiRider does it support nonce? I do have the same problem with @TylerWanta I need to generate nonce for every reload of an app because it only happens when build |
Nope it doesn't support nonce's purely because Single Page Applications typically don't run on a server. If you want nonce support you need a server. I have written up a small guide to help developers out that are either:
If you are using an SPA though you don't need nonce's, hashing at build time is a pretty decent alternative, just harder to implement. Here is a guide for Single Page Applications I know Vite does have an SSR support, so maybe this is something I build into the plugin later, but not for now! |
Describe the bug
I am having the same issue as here, but the solution isn't working for me.
I'm using Electron + Vite and am trying to set a strict CSP (one with no
unsafe-inline
). Since I am using Electron and am not fetching my resources from a server, the nonce specified forcspNonce
is generated right above the config. I then just use a plugin to inject the nonce into the index.html. This works fine in dev when the entire process is ran every time I run the app, but in production the process is only ran when packaging the app and never again. This is problematic as the nonce will no longer be regenerated, defeating the whole purpose. It would be nice if a strict CSP was supported without having to use a nonce.Reproduction
https://github.com/TylerWanta/vite-csp-issue
Steps to reproduce
This will be an issue with any vite build with a strict CSP and no
cspNonce
specified.Clone the repo provided
cd vite-csp-issue
npm run dev
You can see the issue in the console but clicking CTRL + Shift + i
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: