Skip to content

Commit

Permalink
fix: ip targets break private ip check (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykcieszkowski authored Jun 22, 2022
1 parent 9130a8e commit 652eedc
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
61 changes: 52 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"crypto-random-string": "^5.0.0",
"execa": "^6.1.0",
"got": "^12.0.3",
"is-ip": "^4.0.0",
"joi": "^17.6.0",
"lodash": "^4.17.21",
"physical-cpu-count": "^2.0.0",
Expand Down
9 changes: 9 additions & 0 deletions src/command/mtr-command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dns from 'node:dns';
import {isIP} from 'is-ip';
import isIpPrivate from 'private-ip';
import Joi from 'joi';
import type {Socket} from 'socket.io-client';
Expand Down Expand Up @@ -189,6 +190,14 @@ export class MtrCommand implements CommandInterface<MtrOptions> {
}

private async checkForPrivateDest(target: string): Promise<void> {
if (isIP(target)) {
if (isIpPrivate(target)) {
throw new Error('private destination');
}

return;
}

const [ipAddress] = await this.dnsResolver(target);

if (isIpPrivate(String(ipAddress))) {
Expand Down

0 comments on commit 652eedc

Please sign in to comment.