Skip to content
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

feat(plugin-webpack): add devContentSecurityPolicy config option #2332

Merged
merged 1 commit into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/plugin/webpack/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,18 @@ export interface WebpackPluginConfig {
* The TCP port for web-multi-logger. Defaults to 9000.
*/
loggerPort?: number;
/**
* Sets the [`Content-Security-Policy` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy)
* for the Webpack development server.
*
* Normally you would want to only specify this as a `<meta>` tag. However, in development mode,
* the Webpack plugin uses the `devtool: eval-source-map` source map setting for efficiency
* purposes. This requires the `'unsafe-eval'` source for the `script-src` directive that wouldn't
* normally be recommended to use. If this value is set, make sure that you keep this
* directive-source pair intact if you want to use source maps.
*
* Default: `default-src 'self' 'unsafe-inline' data:;`
* `script-src 'self' 'unsafe-eval' 'unsafe-inline' data:`
*/
devContentSecurityPolicy?: string
malept marked this conversation as resolved.
Show resolved Hide resolved
}
7 changes: 7 additions & 0 deletions packages/plugin/webpack/src/WebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ Your packaged app may be larger than expected if you dont ignore everything othe
const config = await this.configGenerator.getRendererConfig(this.config.renderer.entryPoints);
if (!config.plugins) config.plugins = [];
config.plugins.push(pluginLogs);

const cspDirectives = this.config.devContentSecurityPolicy
?? "default-src 'self' 'unsafe-inline' data:; script-src 'self' 'unsafe-eval' 'unsafe-inline' data:";

const compiler = webpack(config);
const webpackDevServer = new WebpackDevServer(compiler, {
hot: true,
Expand All @@ -303,6 +307,9 @@ Your packaged app may be larger than expected if you dont ignore everything othe
},
setupExitSignals: true,
historyApiFallback: true,
headers: {
'Content-Security-Policy': cspDirectives,
},
});
const server = await webpackDevServer.listen(this.port);
this.servers.push(server);
Expand Down