-
-
Notifications
You must be signed in to change notification settings - Fork 469
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
__webpack_nonce__ support or alternative way of solving CSP? #306
Comments
@madjam002 Thanks for issue, need discussion, maybe better implement |
Just to add as well, I've noticed some discussion in #155 regarding CSP, but the way that custom attributes has been implemented there isn't suitable for nonce values as nonce values need to be secure cryptographically generated random strings for each page load and not hard coded into the build |
The way aphrodite solves this is to look for an existing style tag before generating one. In their case something like |
Has there been any progress on this? I'm also working on a site with a strict CSP. |
PR welcome 👍 |
I think this can be closed now since #319 has been merged and included in 0.22.0 |
Also fyi @madjam002 you'll want to just set |
@plondon can you send PR to README about this? |
What's the status with this? Can I use style_loader with a nonce? |
Resolved but confusing docs?
Yes
Make sure the files where you set the nonce is one of the very first imports in the project:
No, webpack_nonce only
Yes |
@plondon maybe you can send a PR to docs ? 😄 anyway thanks for answer |
What's the difference please? when executed from a script, it should be the same __webpack_nonce__ = '..';
window.__webpack_nonce__ = '..';
globalThis.__webpack_nonce__ = '..'; |
As many other "magic variables" webpack will transform So the result of complication will be __webpack_require__.nc = '..';
window.__webpack_nonce__ = '..';
globalThis.__webpack_nonce__ = '..'; But only if complied with webpack. Without it these lines are equal. |
I'm looking at using Webpack on a site which requires strict Content Security Policy headers.
I'm setting
window.__webpack_nonce__
but it doesn't seem to be adding anonce
attribute tostyle
elements created by style-loader. Looking at webpack#3210 it only seems to be adding a nonce attribute to generated script elements? Is there some additional work required in style-loader to support nonce attributes?I don't mind doing a PR, just wanted to make sure first though that I'm not missing something!
The text was updated successfully, but these errors were encountered: