I recently implemented Helmet to establish content security policies for my web application using Express in the backend. The specific policies are as follows:
const express = require("express");
const app = express();
const helmet = require('helmet');
app.use(helmet());
app.use(
helmet.contentSecurityPolicy({
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'", "https://ajax.googleapis.com"],
imgSrc: ["https://firebasestorage.googleapis.com"],
objectSrc: ["'none'"],
styleSrc: ["'self'", "https://maxcdn.bootstrapcdn.com/bootstrap", "https://www.w3schools.com"],
upgradeInsecureRequests: [],
},
})
);
However, I encountered an issue when my app attempted to access a link like
https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css
. It triggered a violation of the styleSrc policy. Even though I had specified that https://maxcdn.bootstrapcdn.com/bootstrap
should be allowed, I assumed that its child source https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css
would also be permitted. Surprisingly, it was blocked. How can I enable the child source to pass through then? I attempted using https://maxcdn.bootstrapcdn.com/bootstrap*
, but it proved to be invalid.