Skip to content

Commit

Permalink
Remove unsafe-inline and self from style-src CSP
Browse files Browse the repository at this point in the history
CSS is now statically inlined so that csp-html-webpack-plugin calculates
hashes for it; this probably doesn't lead to ideal startup performance,
but that's not currently a concern.

See slackhq/csp-html-webpack-plugin#50.
  • Loading branch information
sersorrel committed Mar 17, 2021
1 parent 42fe3ba commit 93aef4b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
58 changes: 55 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@
"@types/react-dom": "^17.0.2",
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"csp-html-webpack-plugin": "^5.1.0",
"csp-html-webpack-plugin": "github:sersorrel/csp-html-webpack-plugin#hash-external-scripts",
"css-loader": "^4.3.0",
"electron": "12.0.1",
"electron-devtools-installer": "^3.1.1",
"eslint": "^7.22.0",
"eslint-plugin-import": "^2.22.1",
"fork-ts-checker-webpack-plugin": "^5.2.1",
"html-inline-css-webpack-plugin": "^1.10.1",
"mini-css-extract-plugin": "^1.3.9",
"node-loader": "^1.0.2",
"style-loader": "^1.3.0",
"ts-loader": "^8.0.18",
Expand Down
6 changes: 5 additions & 1 deletion webpack.plugins.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlInlineCssWebpackPlugin = require('html-inline-css-webpack-plugin').default;
const CspHtmlWebpackPlugin = require('csp-html-webpack-plugin');

module.exports = [
new ForkTsCheckerWebpackPlugin(),
new MiniCssExtractPlugin(),
new HtmlInlineCssWebpackPlugin(),
new CspHtmlWebpackPlugin({
'script-src': "'self'",
'style-src': "'self' 'unsafe-inline'",
'style-src': "",
}, {
nonceEnabled: {
'script-src': false,
Expand Down
4 changes: 3 additions & 1 deletion webpack.renderer.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

const rules = require('./webpack.rules');
const plugins = require('./webpack.plugins');

rules.push({
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
use: [{ loader: MiniCssExtractPlugin.loader }, { loader: 'css-loader' }],
});

module.exports = {
Expand Down

0 comments on commit 93aef4b

Please sign in to comment.