-
Notifications
You must be signed in to change notification settings - Fork 41
Description
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 [ ]
)
- bug
- enhancement (feature request)
- question
- documentation related
- testing related
- discussion
Requirements (place an x
in each of the [ ]
)
- I've read and understood the Contributing guidelines and have done my best effort to follow them.
- I've read and agree to the Code of Conduct.
- I've searched for any related issues and avoided creating a duplicate issue.
Bug Report
If I use this as my webpack configuration:
new HtmlWebpackPlugin( {
filename: "../app/html/webpack_index.html",
template: "app/html/index_template.html",
chunks: [ "app" ],
cspPlugin: {
enabled: true,
policy: {
"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'" ],
},
hashEnabled: {
"script-src": true,
"style-src": true,
},
nonceEnabled: {
"script-src": true,
"style-src": true,
},
},
} ),
new HtmlWebpackPlugin( {
filename: "../app/html/webpack_popup.html",
template: "app/html/popup_template.html",
chunks: [ "form" ],
} ),
new HtmlWebpackPlugin( {
filename: "../app/html/webpack_codemirror.html",
template: "app/html/codemirror_template.html",
chunks: [ "editor" ],
} ),
new HtmlWebpackPlugin( {
filename: "../app/html/webpack_error_wrapper.html",
template: "app/html/error_wrapper_template.html",
chunks: [ "error" ],
} ),
new HtmlWebpackPlugin( {
filename: "../app/html/webpack_documentation.html",
template: "app/html/documentation_template.html",
chunks: [ "docs_entry" ],
} ),
new CspHtmlWebpackPlugin( {
"base-uri": "'self'",
"object-src": "'none'",
"script-src": [ "'unsafe-inline'", "'unsafe-eval'", "https://127.0.0.1:8080", "'self'" ],
"style-src": [ "'unsafe-inline'", "'unsafe-eval'", "https://127.0.0.1:8080", "'self'"],
"font-src": [ "'unsafe-inline'", "'unsafe-eval'", "https://127.0.0.1:8080", "'self'" ],
}, {
enabled: true,
hashingMethod: "sha256",
hashEnabled: {
"script-src": true,
"style-src": true,
},
nonceEnabled: {
"script-src": false,
"style-src": false,
},
} ),
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:
new HtmlWebpackPlugin( {
filename: "../app/html/webpack_index.html",
template: "app/html/index_template.html",
chunks: [ "app" ],
cspPlugin: {
enabled: true,
policy: {
"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'" ],
},
hashEnabled: {
"script-src": true,
"style-src": true,
},
nonceEnabled: {
"script-src": false,
"style-src": false,
},
},
} ),
new HtmlWebpackPlugin( {
filename: "../app/html/webpack_popup.html",
template: "app/html/popup_template.html",
chunks: [ "form" ],
} ),
new HtmlWebpackPlugin( {
filename: "../app/html/webpack_codemirror.html",
template: "app/html/codemirror_template.html",
chunks: [ "editor" ],
} ),
new HtmlWebpackPlugin( {
filename: "../app/html/webpack_error_wrapper.html",
template: "app/html/error_wrapper_template.html",
chunks: [ "error" ],
} ),
new HtmlWebpackPlugin( {
filename: "../app/html/webpack_documentation.html",
template: "app/html/documentation_template.html",
chunks: [ "docs_entry" ],
} ),
new CspHtmlWebpackPlugin( {
"base-uri": "'self'",
"object-src": "'none'",
"script-src": [ "'unsafe-inline'", "'unsafe-eval'", "https://127.0.0.1:8080", "'self'" ],
"style-src": [ "'unsafe-inline'", "'unsafe-eval'", "https://127.0.0.1:8080", "'self'"],
"font-src": [ "'unsafe-inline'", "'unsafe-eval'", "https://127.0.0.1:8080", "'self'" ],
}, {
enabled: true,
hashingMethod: "sha256",
hashEnabled: {
"script-src": true,
"style-src": true,
},
nonceEnabled: {
"script-src": false,
"style-src": false,
},
} ),
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