diff --git a/src/meta/blacklist.js b/src/meta/blacklist.js index 20f0e441ff..31af5f9eee 100644 --- a/src/meta/blacklist.js +++ b/src/meta/blacklist.js @@ -71,8 +71,11 @@ Blacklist.test = function (clientIp, callback) { Blacklist._rules.ipv4.indexOf(clientIp) === -1 && // not explicitly specified in ipv4 list Blacklist._rules.ipv6.indexOf(clientIp) === -1 && // not explicitly specified in ipv6 list !Blacklist._rules.cidr.some(function (subnet) { - return addr.match(ipaddr.parseCIDR(subnet)); - // return ip.cidrSubnet(subnet).contains(clientIp); + var cidr = ipaddr.parseCIDR(subnet); + if (addr.kind() !== cidr[0].kind()) { + return false; + } + return addr.match(cidr); }) // not in a blacklisted IPv4 or IPv6 cidr range ) { plugins.fireHook('filter:blacklist.test', { // To return test failure, pass back an error in callback diff --git a/test/blacklist.js b/test/blacklist.js index d003739d8f..763c5364f7 100644 --- a/test/blacklist.js +++ b/test/blacklist.js @@ -72,4 +72,9 @@ describe('blacklist', function () { assert(blacklist.test('1.1.1.1')); done(); }); + + it('should pass ip test and not crash with ipv6 address', function (done) { + assert(!blacklist.test('2001:db8:85a3:0:0:8a2e:370:7334')); + done(); + }); });