Added support for DNS name in TLSOffload and TrustedProxy settings.

Ylian Saint-Hilaire committed Jan 4, 2021 at 01:50 UTC 1318f3498cf32a9b94012a6ae4189894baf899d0
1 file changed +22 -2
webserver.js
+22 -2
@@ -4909,8 +4909,28 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4909 // Setup middleware
4910 obj.app.engine('handlebars', obj.exphbs({ defaultLayout: null })); // defaultLayout: 'main'
4911 obj.app.set('view engine', 'handlebars');
4912 - if (obj.args.trustedproxy) { obj.app.set('trust proxy', obj.args.trustedproxy); } // Reverse proxy should add the "X-Forwarded-*" headers
4913 - else if (typeof obj.args.tlsoffload == 'object') { obj.app.set('trust proxy', obj.args.tlsoffload); } // Reverse proxy should add the "X-Forwarded-*" headers
4912 + if (obj.args.trustedproxy) {
4913 + // Reverse proxy should add the "X-Forwarded-*" headers
4914 + try {
4915 + obj.app.set('trust proxy', obj.args.trustedproxy);
4916 + } catch (ex) {
4917 + // If there is an error, try to resolve the string
4918 + if ((obj.args.trustedproxy.length == 1) && (typeof obj.args.trustedproxy[0] == 'string')) {
4919 + require('dns').lookup(obj.args.trustedproxy[0], function(err, address, family) { if (err == null) { obj.app.set('trust proxy', address); } });
4920 + }
4921 + }
4922 + }
4923 + else if (typeof obj.args.tlsoffload == 'object') {
4924 + // Reverse proxy should add the "X-Forwarded-*" headers
4925 + try {
4926 + obj.app.set('trust proxy', obj.args.tlsoffload);
4927 + } catch (ex) {
4928 + // If there is an error, try to resolve the string
4929 + if ((obj.args.tlsoffload.length == 1) && (typeof obj.args.tlsoffload[0] == 'string')) {
4930 + require('dns').lookup(obj.args.tlsoffload[0], function (err, address, family) { if (err == null) { obj.app.set('trust proxy', address); } });
4931 + }
4932 + }
4933 + }
4934 obj.app.use(obj.bodyParser.urlencoded({ extended: false }));
4935 var sessionOptions = {
4936 name: 'xid', // Recommended security practice to not use the default cookie name