Skip to content

Commit

Permalink
feat: add helmet middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Aug 4, 2020
1 parent 6812691 commit 774e5d0
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/webserver.js
Expand Up @@ -164,14 +164,7 @@ function setupExpressApp(app) {
saveUninitialized: nconf.get('sessionSaveUninitialized') || false,
}));

app.use(helmet.referrerPolicy({ policy: 'strict-origin-when-cross-origin' }));
if (meta.config['hsts-enabled']) {
app.use(helmet.hsts({
maxAge: meta.config['hsts-maxage'],
includeSubDomains: !!meta.config['hsts-subdomains'],
preload: !!meta.config['hsts-preload'],
}));
}
setupHelmet(app);

app.use(middleware.addHeaders);
app.use(middleware.processRender);
Expand All @@ -183,6 +176,27 @@ function setupExpressApp(app) {
toobusy.interval(meta.config.eventLoopInterval);
}

function setupHelmet(app) {
app.use(helmet.dnsPrefetchControl());
app.use(helmet.expectCt());
app.use(helmet.frameguard());
app.use(helmet.hidePoweredBy());
app.use(helmet.ieNoOpen());
app.use(helmet.noSniff());
app.use(helmet.permittedCrossDomainPolicies());
app.use(helmet.xssFilter());

app.use(helmet.referrerPolicy({ policy: 'strict-origin-when-cross-origin' }));
if (meta.config['hsts-enabled']) {
app.use(helmet.hsts({
maxAge: meta.config['hsts-maxage'],
includeSubDomains: !!meta.config['hsts-subdomains'],
preload: !!meta.config['hsts-preload'],
}));
}
}


function setupFavicon(app) {
var faviconPath = meta.config['brand:favicon'] || 'favicon.ico';
faviconPath = path.join(nconf.get('base_dir'), 'public', faviconPath.replace(/assets\/uploads/, 'uploads'));
Expand Down

0 comments on commit 774e5d0

Please sign in to comment.