-
Notifications
You must be signed in to change notification settings - Fork 1
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
Nonces still getting inserted even after I set nonceEnabled to false #104
Comments
it sounds like you have it configured incorrectly? Just set // utilities
const { override } = require('customize-cra');
// plugins
const CspHtmlWebpackPlugin = require("@melloware/csp-webpack-plugin");
const cspConfigPolicy = {
'default-src': "'none'",
'object-src': "'none'",
'base-uri': "'self'",
'connect-src': "'self' blob: localhost:* *.microsoftonline.com",
'worker-src': "'self' blob:",
'img-src': "'self' blob: data: content:",
'font-src': "'self'",
'frame-src': "'self'",
'manifest-src': "'self'",
'style-src': ["'self'"],
'script-src': ["'strict-dynamic'"],
'require-trusted-types-for': ["'script'"]
};
// Enable CSP and SRI. See https://github.com/melloware/csp-webpack-plugin
const cspPlugin = new CspHtmlWebpackPlugin(cspConfigPolicy);
// cache busting string instead of random hash so all pods serve the same files
var currentDate = new Date();
var version = `${currentDate.getFullYear()}${currentDate.getMonth()+1}${currentDate.getDate()}`
// add all plugins to Webpack pipeline in correct order
function addPlugins(config, env) {
if (env !== 'production') {
return config;
}
// CSP plugin
config.plugins.push(cspPlugin);
config.output.crossOriginLoading = "anonymous";
// Get rid of hash for js files
config.output.filename = `static/js/[name]-${version}.js`
config.output.chunkFilename = `static/js/[name]-${version}.chunk.js`
// Get rid of hash for css files
const miniCssExtractPlugin = config.plugins.find(element => element.constructor.name === "MiniCssExtractPlugin");
miniCssExtractPlugin.options.filename = `static/css/[name]-${version}.css`
miniCssExtractPlugin.options.chunkFilename = `static/css/[name]-${version}.css`
return config;
}
module.exports = {
webpack: override(addPlugins),
}; |
@melloware I have copied your exact code into my config-overrides.js (just changed the style-src to unsafe-inline), and the nonces still get injected into index.html. This is my config-overrides.js file:
This is injected into index.html after build:
|
Hmmm can you try with the ogiinal CSP plugin? I don't think I have touched anything from the original plugin? |
Besides |
Thanks @NotAndOr that is probably my fault when I added that option to this plug-in! |
I'm creating a static app with CRA and even though I specify the nonceEnabled to be false in the config of this package, it still automatically inserts nonces.
I'm using styled-components and I need the style-src attribute to be unsafe-inline, but the automatically inserted nonce keeps overwriting it (if there is a nonce/hash, unsafe-inline will be ignored)
Is this a bug or am I misunderstanding the nonceEnabled and hashEnabled properties?
The text was updated successfully, but these errors were encountered: