nonce tag in __vitePreload (CSP)
See original GitHub issueDescription
I am trying to migrate or default tooling from Webpack to Vite.
The main issue is nonce security police.
Actually, we handle it using __webpack_nonce__
https://webpack.js.org/guides/csp/
I can’t interact with the preload function to change it.
I’m already injecting the preload tags manually, JavaScript and CSS files.
Suggested solution
A way to inject nonce value simular to webpack.
Alternative
No response
Additional context
Example Application
https://github.com/nextcloud/text/blob/48b21b6e524c4aef78a1046e1f19a2bbd85837c4/src/main.js#L3-L4
Nextcloud apps
Nextcloud is modular, and allow the users to install a variety of apps. These apps can inject scripts in many parts of nextcloud.
For secure reasons, we use CSP to prevent malicious script injections.
Content-Security-Policy: default-src 'none';base-uri 'none';manifest-src 'self';script-src 'nonce-cHQ...bz0=';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-src 'self';frame-ancestors 'self';form-action 'self'
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that request the same feature to avoid creating a duplicate.
Issue Analytics
- State:
- Created a year ago
- Reactions:12
- Comments:6
Top Results From Across the Web
Content Security Policies - webpack
Webpack is capable of adding a nonce to all scripts that it loads. To activate this feature, set a __webpack_nonce__ variable and include...
Read more >Vite on Twitter: " vite@3.2.0-beta.1 is out! https://t.co ...
Description I am trying to migrate or default tooling from Webpack to Vite. The main issue is nonce security police. Actually, we handle...
Read more >702612 - CSP nonce is not applied to Link rel=preload
Issue 702612: CSP nonce is not applied to Link rel=preload ... The `Link` tag should use the `nonce` attribute to preload the script,...
Read more >SvelteKit Content Security Policy: CSP for XSS Protection
To avoid calculating a hash on each request, we instead generate a random string; a nonce. We include the nonce it script tags...
Read more >Asset Bundling (Vite) - The PHP Framework For Web Artisans
... Disabling Vite In Tests; Server-Side Rendering (SSR); Script & Style Tag Attributes. Content Security Policy (CSP) Nonce; Subresource Integrity (SRI) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Running into this issue too. I’m disabling all the dynamic import because I could not set the nonce token on the generated tags. Waiting for a solution
I’m just now running into this as well. I converted our apps to Vite a few months ago and I love using it, it’s SO FAST.
I’ve done a little googling trying to figure out if there is a plugin that will do this and I haven’t found anything.
Do we have any updates on this issue?