Add option to enable/disable HSTS

Also fix HSTS middleware being added twice.
This commit is contained in:
Jimb Esser
2018-08-06 18:24:57 -07:00
committed by Julian Lam
parent 4027abcd58
commit 3cccbbc1f2
3 changed files with 17 additions and 4 deletions

View File

@@ -185,13 +185,19 @@ function setupExpressApp(app, callback) {
saveUninitialized: true,
}));
app.use(helmet());
app.use(helmet.referrerPolicy({ policy: 'strict-origin-when-cross-origin' }));
app.use(helmet.hsts({
var hsts_option = {
maxAge: parseInt(meta.config['hsts-maxage'], 10) || 31536000,
includeSubdomains: !!parseInt(meta.config['hsts-subdomains'], 10),
preload: !!parseInt(meta.config['hsts-preload'], 10),
setIf: function () {
// If not set, default to on - previous and recommended behavior
return meta.config['hsts-enabled'] === undefined || !!parseInt(meta.config['hsts-enabled'], 10);
},
};
app.use(helmet({
hsts: hsts_option,
}));
app.use(helmet.referrerPolicy({ policy: 'strict-origin-when-cross-origin' }));
app.use(middleware.addHeaders);
app.use(middleware.processRender);
auth.initialize(app, middleware);