CSP: Remove global this in webpack

Also refactor how we handle global namespace objects.

Fixes CODEOCEAN-DV
This commit is contained in:
Sebastian Serth
2022-11-16 16:44:23 +01:00
parent e0bce2071e
commit b9f3126f21
3 changed files with 6 additions and 17 deletions

View File

@ -14,8 +14,8 @@ import * as bootstrap from 'bootstrap/dist/js/bootstrap.bundle';
import 'chosen-js/chosen.jquery'; import 'chosen-js/chosen.jquery';
import 'jstree'; import 'jstree';
import 'underscore'; import 'underscore';
import 'd3'; import * as d3 from 'd3';
import '@sentry/browser'; import * as Sentry from '@sentry/browser';
import 'sorttable'; import 'sorttable';
window.bootstrap = bootstrap; // Publish bootstrap in global namespace window.bootstrap = bootstrap; // Publish bootstrap in global namespace
window._ = _; // Publish underscore's `_` in global namespace window._ = _; // Publish underscore's `_` in global namespace

View File

@ -1,7 +1,7 @@
/* eslint no-console:0 */ /* eslint no-console:0 */
// JS // JS
import 'vis' import * as vis from 'vis';
window.vis = vis; window.vis = vis;
// CSS // CSS

View File

@ -19,6 +19,9 @@ const relative_url_root = process.env.RAILS_RELATIVE_URL_ROOT || '';
const public_output_path = webpackConfig.output.publicPath; const public_output_path = webpackConfig.output.publicPath;
const envConfig = module.exports = { const envConfig = module.exports = {
node: {
global: false,
},
module: { module: {
rules: [ rules: [
erb erb
@ -41,20 +44,6 @@ const envConfig = module.exports = {
hints: false hints: false
}, },
plugins: [ plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
JQuery: 'jquery',
jQuery: 'jquery',
jquery: 'jquery',
'window.Tether': "tether",
Popper: ['popper.js', 'default'],
_: 'underscore',
vis: 'vis',
d3: 'd3',
Sentry: '@sentry/browser',
Sortable: 'sortablejs',
sorttable: 'sorttable',
}),
new CompressionPlugin(), new CompressionPlugin(),
new MiniCssExtractPlugin(), new MiniCssExtractPlugin(),
new SubresourceIntegrityPlugin(), new SubresourceIntegrityPlugin(),