Repository navigation
added nonce capability - #3210
Conversation
|
Could you explain why you need this nonce attribute on the script tag? From what I know it's only required for inline script tags... cc @samertm |
|
Recent research out of Google suggests that using nonces for external scripts as well as inline scripts is a better way to write CSPs, since it avoids problems with transitive trust given to certain external sources. https://research.google.com/pubs/pub45542.html |
|
+1, we're planning on using this patch at Dropbox |
| __webpack_nonce__ = 'nonce1234'; | ||
| require.ensure([], function(require) { | ||
| require("./empty?a"); | ||
| }, "chunk-with-nonce"); |
| __webpack_nonce__ = undefined; | ||
| // if in browser context, test that nonce was added. | ||
| if (typeof document !== 'undefined') { | ||
| var script = document.querySelector('script[src="js/chunk-with-nonce.web.js"]'); |
| it("should load script without nonce", function(done) { | ||
| require.ensure([], function(require) { | ||
| require("./empty?b"); | ||
| }, "chunk-without-nonce"); |
| // if in browser context, test that nonce was added. | ||
| if (typeof document !== 'undefined') { | ||
| var script = document.querySelector('script[src="js/chunk-without-nonce.web.js"]'); | ||
| script.hasAttribute('nonce').should.be.eql(false); |
|
Pling Please at least sign the CLA so another person can pick up your commit and continue it. |
|
I've made the necessary changes, but unfortunately there's another merge conflict in the stats test cases. I'm on a different computer now than I was, but all that I need to do is run those test cases and figure out what the new outputs should be – I'm just not sure what I need to install to do this. Can someone point me in the right direction? I installed Yarn, but it doesn't seem to be working (various packages missing) and before I go down that rabbit hole, I was wondering whether there was an easier way to just run the single Stats.test.js file. I'd really like to get this done soon, and since I'm on Thanksgiving break from school I should actually be able to finish it all quickly once I get these tests running. |
npm install
npm link
npm link webpack
npm test
node test/statsCases/accept-stats.jsinstead of Make sure to run |
|
PR looks great. I'll merge it once you signed the CLA. Make sure your commits include the correct email. |
change expected outputs of stats cases so they match new output added nonce test to browser tests
|
Email issue should be fixed now! |
|
Great thanks for the PR |
|
@lunasofia Thanks for this addition. I can't get it to work since there is no documentation found anywhere about this. Any hints? Should I just add |
|
@ruudk you should set it in your index.js file, I believe |
|
Hello @lunasofia. Is there any documentation about this feature and how to implement it? I assume I need to set the webpack_nonce = "myToken" somewhere in a config file but I don't know where. You specified an index.js, can you, please, tell me where it is? My application uses : |
|
@lunasofia @sokra, I'm trying to wrap my head around this and I feel like I'm missing something very obvious. I've added the magic string in my app's entry point, e.g. Is there something in my webpack config that I need to add as well to "nonce"ify my inline scripts injected by webpack? |
|
Hi! I'm so sorry I haven't been responding to questions here. I worked on this for an internship, and did not have the time to keep up to date on the project after my internship ended. It's likely that @samertm will be able to answer your questions. |
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
What is the current behavior? (You can also link to an open issue here)
#455
Currently, webpack does provide a way to add nonces to scripts. Given that the future of CSP could be a more nonce-based approach, having support for nonces is increasingly important.
https://research.google.com/pubs/pub45542.html
What is the new behavior?
When user specifies webpack_nonce, a nonce is added to all loaded scripts. Because nonces are generally different on each page load, the nonce is specified in the entry file, not in the config file, similarly to a public path not known ahead of time.
Does this PR introduce a breaking change?
If this PR contains a breaking change, please describe the following...
Other information: