Trusted proxy DNS resolve improvements.

Ylian Saint-Hilaire committed Jan 5, 2021 at 12:52 UTC b3507445f58e568b944dee767d06416149455b83
1 file changed +3 -3
webserver.js
+3 -3
@@ -4917,7 +4917,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4917 } catch (ex) {
4918 // If there is an error, try to resolve the string
4919 if ((obj.args.trustedproxy.length == 1) && (typeof obj.args.trustedproxy[0] == 'string')) {
4920 - require('dns').lookup(obj.args.trustedproxy[0], function(err, address, family) { if (err == null) { obj.app.set('trust proxy', address); } });
4920 + require('dns').lookup(obj.args.trustedproxy[0], function (err, address, family) { if (err == null) { obj.app.set('trust proxy', address); obj.args.trustedproxy = [address]; } });
4921 }
4922 }
4923 }
@@ -4928,7 +4928,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4928 } catch (ex) {
4929 // If there is an error, try to resolve the string
4930 if ((obj.args.tlsoffload.length == 1) && (typeof obj.args.tlsoffload[0] == 'string')) {
4931 - require('dns').lookup(obj.args.tlsoffload[0], function (err, address, family) { if (err == null) { obj.app.set('trust proxy', address); } });
4931 + require('dns').lookup(obj.args.tlsoffload[0], function (err, address, family) { if (err == null) { obj.app.set('trust proxy', address); obj.args.tlsoffload = [address]; } });
4932 }
4933 }
4934 }
@@ -4950,7 +4950,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4950 var ipex = '0.0.0.0', xforwardedhost = req.headers.host;
4951 if (typeof req.connection.remoteAddress == 'string') { ipex = (req.connection.remoteAddress.startsWith('::ffff:')) ? req.connection.remoteAddress.substring(7) : req.connection.remoteAddress; }
4952 if (
4953 - (obj.args.trustedproxy === true) ||
4953 + (obj.args.trustedproxy === true) || (obj.args.tlsoffload === true) ||
4954 ((typeof obj.args.trustedproxy == 'object') && (isIPMatch(ipex, obj.args.trustedproxy))) ||
4955 ((typeof obj.args.tlsoffload == 'object') && (isIPMatch(ipex, obj.args.tlsoffload)))
4956 ) {