-
Notifications
You must be signed in to change notification settings - Fork 41
Not getting hashes in meta tag #35
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
Comments
We have the same question and are observing similar behavior, except in our case, we don't want the nonce included. Setting
or seems to have no affect....the nonce is always included and the hash is never included (have not tested the validy of the nonce) slackhq/csp-html-webpack-plugin version: 3.0.1 |
Here is the template html file at least: `
You can see I have commented out a CSP meta tag. Under some circumstances, that I was unable to reproduce when I came to report the issue, the plugin did nothing and I just got the template CSP (hence those capitals, just to be clear where the CSP was coming from). A demo repo may take a little lnger, but I'll try and get you one. |
The CSP plugin will only add In your template above, there are no inline However, it's possible you could inject script blocks into your template during webpack compile time - we do so by using If you're adding script blocks after webpack has output it's assets, these won't be included in the CSP policy, and will be blocked during runtime. It's recommended that you disable this plugin when developing locally, especially if using webpack-dev-server / hot module replacement, as you'll be changing assets in memory, and their contents won't be rehashed each time. If you're seeing something else from this, a minimal repo would be incredibly useful for me to debug this! @duntonr hopefully this answers your question too, otherwise a minimal repo would be appreciate too :) Thanks |
@AnujRNair - ahh, sorry, I thought I had replied. |
I'm going to close this for now, since I believe this to be answered, but if you need any more clarification, please let me know and I will reopen this issue |
@AnujRNair, yes, thanks very much that's fair. I'll report back on the progress I make with the other plugin. |
Im having this issue as well. Unfortunately, I dont have a minimal repo but addStyles is getting borked as original poster stated. Also, only using this plugin in production does not alleviate the issues in production. |
My guess here is that the add style calls are being eval'ed, or your policy is too strict - without a repo it's hard to tell exactly whats happening here :( |
@AnujRNair just a quick follow-up. I have now tested this plugin with the script added inline as you stated and it worked exactly as expected, so nothing for you to do there. For the benefit of those that follow along after me: With regard to the other plugin that you mentioned, I also looked into using a variant of this approach which uses embedded javascript. I am still trying to figure out how to handle this in the longer term, for the moment I am just using the hash provided in the console error message. |
@AnujRNair is there any plan to include hashes for linked scripts? We can't get The docs also don't seem to indicate that this is the case:
|
Uh oh!
There was an error while loading. Please reload this page.
Description
I am not seeing hashes in the meta tag when I expected I would. I do seem to get nonces, but they don't appear to work.
What type of issue is this? (place an
x
in one of the[ ]
)Requirements (place an
x
in each of the[ ]
)Bug Report
If I use this as my webpack configuration:
then it produces this output (for the app chunk):
<meta http-equiv="Content-Security-Policy" content="base-uri 'self'; object-src 'none'; script-src https://127.0.0.1:8080 'self' 'nonce-iy87WccFQS7zHW0XbzFJCw=='; style-src https://127.0.0.1:8080 'self' 'nonce-eqk3Sox+amk9wfdSl3g5GQ=='; font-src 'unsafe-inline' 'unsafe-eval' https://127.0.0.1:8080 'self'>
and I see this error:
<meta http-equiv="Content-Security-Policy" content="base-uri 'self'; object-src 'none'; script-src https://127.0.0.1:8080 'self' 'nonce-iy87WccFQS7zHW0XbzFJCw=='; style-src https://127.0.0.1:8080 'self' 'nonce-eqk3Sox+amk9wfdSl3g5GQ=='; font-src 'unsafe-inline' 'unsafe-eval' https://127.0.0.1:8080 'self'; connect-src 'unsafe-inline' 'unsafe-eval' https://127.0.0.1:8080 'self' https://ipv4.icanhazip.com wss://127.0.0.1:8080 https://api.keygen.sh">
which is coming from addStyles.js, part of the style-loader package.
If I now set the nonce enabled to be false, as below:
then it produces this output (for the app chunk):
<meta http-equiv="Content-Security-Policy" content="base-uri 'self'; object-src 'none'; script-src https://127.0.0.1:8080 'self'; style-src https://127.0.0.1:8080 'self'; font-src 'unsafe-inline' 'unsafe-eval' https://127.0.0.1:8080 'self'>
and I see this error:
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src https://127.0.0.1:8080 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='), or a nonce ('nonce-...') is required to enable inline execution.
If I delete the nonceEnabled section in the app chunk settings then I get the same result as setting them to false.
So my questions are why am I not getting hashed generated and what do I need to do so that thye are generated and secondly, why is the nonce that is generated not working - how can I tell what the nonce relates to ?
Thanks for your help.
Reproducible in:
slackhq/csp-html-webpack-plugin version: 3.0.1
node version: 10.13
OS version(s): Windows 10
Steps to reproduce:
As its a question I have not tried to reproduce the issue in a cut down setup.
Expected result:
Expected to see hashes inserted into the meta tag
Actual result:
Nonces were inserted, but seemed to have no effect.
Attachments:
None
The text was updated successfully, but these errors were encountered: