2020-09-01 21:19:46 +02:00
|
|
|
const helmet = require('helmet');
|
|
|
|
|
|
|
|
module.exports = function(config) {
|
2020-10-01 21:47:40 +02:00
|
|
|
if (config.secureHeaders) {
|
2020-09-01 21:19:46 +02:00
|
|
|
return helmet({
|
2020-09-18 11:30:30 +02:00
|
|
|
hsts: {
|
|
|
|
maxAge: 63072000,
|
|
|
|
includeSubDomains: true,
|
|
|
|
preload: true,
|
|
|
|
},
|
2020-09-01 21:19:46 +02:00
|
|
|
contentSecurityPolicy: {
|
|
|
|
directives: {
|
2020-10-01 21:47:40 +02:00
|
|
|
defaultSrc: ["'self'"],
|
|
|
|
fontSrc: [
|
2020-09-01 21:19:46 +02:00
|
|
|
"'self'",
|
|
|
|
'fonts.googleapis.com',
|
|
|
|
'fonts.gstatic.com',
|
|
|
|
],
|
2020-09-07 09:23:59 +02:00
|
|
|
styleSrc: [
|
|
|
|
"'self'",
|
2020-09-07 09:51:30 +02:00
|
|
|
"'unsafe-inline'",
|
2020-09-07 09:23:59 +02:00
|
|
|
'fonts.googleapis.com',
|
|
|
|
'fonts.gstatic.com',
|
|
|
|
'data:',
|
|
|
|
],
|
2020-10-01 21:47:40 +02:00
|
|
|
scriptSrc: ["'self'"],
|
|
|
|
imgSrc: ["'self'", 'data:', 'gravatar.com'],
|
2020-09-01 21:19:46 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return (req, res, next) => {
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
};
|