From 8af531b4b028a1561a3212767c6d1f600530549c Mon Sep 17 00:00:00 2001 From: titanism <101466223+titanism@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:40:45 -0500 Subject: [PATCH] fix: fixed hostname lookup causing uncaught exception --- helpers/is-allowlisted.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/helpers/is-allowlisted.js b/helpers/is-allowlisted.js index da682cca76..7017677f37 100644 --- a/helpers/is-allowlisted.js +++ b/helpers/is-allowlisted.js @@ -15,6 +15,7 @@ const { isEmail } = require('validator'); const config = require('#config'); const env = require('#config/env'); +const logger = require('#helpers/logger'); const parseHostFromDomainOrAddress = require('#helpers/parse-host-from-domain-or-address'); const parseRootDomain = require('#helpers/parse-root-domain'); @@ -75,18 +76,26 @@ async function isAllowlisted(val, client, resolver) { const root = parseRootDomain(val); if (root === env.WEB_HOST) return true; } else if (isIP(val)) { - // reverse lookup IP and if it was allowlisted then return early - const [clientHostname] = await resolver.reverse(val); - if (isFQDN(clientHostname)) { - // check domain - if (await isAllowlisted(clientHostname, client, resolver)) return true; - // check root domain (if differed) - const root = parseRootDomain(clientHostname); - if ( - clientHostname !== root && - (await isAllowlisted(root, client, resolver)) - ) - return true; + try { + // reverse lookup IP and if it was allowlisted then return early + const [clientHostname] = await resolver.reverse(val); + if (isFQDN(clientHostname)) { + // check domain + if (await isAllowlisted(clientHostname, client, resolver)) return true; + // check root domain (if differed) + const root = parseRootDomain(clientHostname); + if ( + clientHostname !== root && + (await isAllowlisted(root, client, resolver)) + ) + return true; + } + } catch (err) { + // + // NOTE: the native Node.js DNS module would throw an error previously + // + // + if (env.NODE_ENV !== 'production') logger.debug(err); } }