From a680331dd77902a160e7876f650f5204e26d0499 Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Fri, 15 Apr 2022 19:59:32 +0100 Subject: [PATCH] Fixes issue with ::1 port 5300 requests Now the address is wrapped in `[]` in order to prevent ::1 port 5300 being interpreted as ::1:5300. Wrapping the IPv4 address in `[]` does seem to have any effect on correct domain name resolution. In order to prevent issues if a user inputs an address with brackets, they are removed from the string if present before being re-added when it is passed to `setServers`. I have also removed the JSDoc comment as this will be added in a seperate PR Signed-off-by: Matthew Nickson --- server/util-server.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/server/util-server.js b/server/util-server.js index 367f4ffb..f7c0ce02 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -88,17 +88,12 @@ exports.pingAsync = function (hostname, ipv6 = false) { }); }; -/** - * Resolves a given record using the specified DNS server - * @param {string} hostname The hostname of the record to lookup - * @param {string} resolver_server The DNS server to use - * @param {string} resolver_port The port the DNS server is listening on - * @param {string} rrtype The type of record to request - * @returns {Promise} Promise object represents DNS lookup result - */ exports.dnsResolve = function (hostname, resolver_server, resolver_port, rrtype) { const resolver = new Resolver(); - resolver.setServers([`${resolver_server}:${resolver_port}`]); + // Remove brackets from IPv6 addresses so we can re-add them to + // prevent issues with ::1:5300 (::1 port 5300) + resolver_server = resolver_server.replace("[", "").replace("]", ""); + resolver.setServers([`[${resolver_server}]:${resolver_port}`]); return new Promise((resolve, reject) => { if (rrtype == "PTR") { resolver.reverse(hostname, (err, records) => {