I am trying to write a simple NodeJS HTTPS web server using HTTPS and Express that has a configurable Content-Security-Policy.
I try to set the Content-Security-Policy header attribute in the server response object, but always just sends "default-src 'self'". it appears that the HTTPS module overwrites whatever I specify.
I have also tried using the helmet-csp npm package with no success either.
Here's my code snippet:
var app = express();
var sslOptions = {
cert: fs.readFileSync(ourPath + "/certs/server.crt"),
key: fs.readFileSync(ourPath + "/certs/server.pem")
};
var httpsServer = https.createServer(sslOptions, app);
var server = httpsServer.listen(secPort /*443*/, function () {
console.log('HTTPS Server listening at port %d', secPort);
});
// Trap the incoming request, and preset the CSP in the response header
server.on('request',(req,res)=>{
res.setHeader("Content-Security-policy","* 'inline-eval';");
});