Skip to content

Commit

Permalink
fix: fix defaultIPChecker when ip is v6 format
Browse files Browse the repository at this point in the history
  • Loading branch information
welefen committed Nov 18, 2021
1 parent cec2b85 commit 9607175
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { Agent: HttpAgent } = require('http');
const { Agent: HttpsAgent } = require('https');
const { isPrivate, isV4Format } = require('ip');
const { isPrivate, isV4Format, isV6Format } = require('ip');
const httpAgent = new HttpAgent();
const httpsAgent = new HttpsAgent();

Expand All @@ -11,7 +11,7 @@ const getAgent = agent => {
};

const defaultIpChecker = ip => {
if (isV4Format(ip)) {
if (isV4Format(ip) || isV6Format(ip)) {
return !isPrivate(ip);
}

Expand All @@ -20,7 +20,7 @@ const defaultIpChecker = ip => {

const CREATE_CONNECTION = Symbol('createConnection');

module.exports = function(
module.exports = function (
ipChecker = defaultIpChecker,
agent = 'http'
) {
Expand All @@ -33,7 +33,7 @@ module.exports = function(
agent[CREATE_CONNECTION] = true;

const createConnection = agent.createConnection;
agent.createConnection = function(options, fn) {
agent.createConnection = function (options, fn) {
const { host: address } = options;
if (!ipChecker(address)) {
throw new Error(`DNS lookup ${address} is not allowed.`);
Expand Down

0 comments on commit 9607175

Please sign in to comment.