mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
WeKan sent no HSTS header, so a link typed as plain HTTP or a downgrade on a hostile network could strip TLS from the next visit unless the reverse proxy added it. It is now sent whenever ROOT_URL is https: 180 days, this host only. HSTS_MAX_AGE, HSTS_INCLUDE_SUBDOMAINS and HSTS_PRELOAD (Admin Panel / People / Login, every platform) change it; 0 stops it, and preload is sent only with includeSubDomains and at least a year. Every response also carries X-Content-Type-Options: nosniff and Referrer-Policy: strict-origin-when-cross-origin. Thanks to xet7 !
22 lines
862 B
JavaScript
22 lines
862 B
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { WebApp } from 'meteor/webapp';
|
|
import { authEnv } from '/server/lib/authConfig';
|
|
|
|
// Strict-Transport-Security, X-Content-Type-Options and Referrer-Policy on
|
|
// every response; what they are and when HSTS is sent is
|
|
// models/lib/securityHeaders.js. A rawHandler runs before every other handler,
|
|
// static files included, and a route that sets one of these headers itself
|
|
// (the file routes do) overwrites it after this.
|
|
const { securityHeaders } = require('/models/lib/securityHeaders');
|
|
|
|
WebApp.rawHandlers.use((req, res, next) => {
|
|
try {
|
|
for (const [name, value] of securityHeaders(authEnv, process.env.ROOT_URL || Meteor.absoluteUrl())) {
|
|
if (!res.headersSent) res.setHeader(name, value);
|
|
}
|
|
} catch (e) {
|
|
// A header that cannot be computed must not fail the request.
|
|
}
|
|
next();
|
|
});
|