From e3c8b688b35027d18ba0672421771860ff9915a1 Mon Sep 17 00:00:00 2001 From: Victor Elias Date: Fri, 5 Apr 2024 16:46:05 +0200 Subject: [PATCH] api/cannon: Handle IP hostnames gracefully --- packages/api/src/webhooks/cannon.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/api/src/webhooks/cannon.ts b/packages/api/src/webhooks/cannon.ts index eea62333cb..3edac3ae51 100644 --- a/packages/api/src/webhooks/cannon.ts +++ b/packages/api/src/webhooks/cannon.ts @@ -1,4 +1,5 @@ import { ConsumeMessage } from "amqplib"; +import { isIP } from "net"; import dns from "dns"; import isLocalIP from "is-local-ip"; import { Response } from "node-fetch"; @@ -452,11 +453,13 @@ export default class WebhookCannon { throw err; }; - const urlObj = parseUrl(url); - const ips = await Promise.all([ - this.resolver.resolve4(urlObj.hostname).catch(emptyIfNotFound), - this.resolver.resolve6(urlObj.hostname).catch(emptyIfNotFound), - ]).then((ipsArrs) => ipsArrs.flat()); + const { hostname } = parseUrl(url); + const ips = isIP(hostname) + ? [hostname] + : await Promise.all([ + this.resolver.resolve4(hostname).catch(emptyIfNotFound), + this.resolver.resolve6(hostname).catch(emptyIfNotFound), + ]).then((ipsArrs) => ipsArrs.flat()); const isLocal = ips.some(isLocalIP); return { ips, isLocal };