Skip to content

Commit

Permalink
api/cannon: Handle IP hostnames gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Apr 22, 2024
1 parent f39ea86 commit e3c8b68
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/api/src/webhooks/cannon.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 };
Expand Down

0 comments on commit e3c8b68

Please sign in to comment.