From 7799efa8936adf90bd22c4203be52ea6f21d8437 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 21 Aug 2020 09:33:07 -0700 Subject: [PATCH] net: make blocklist family case insensitive Signed-off-by: James M Snell PR-URL: https://github.com/nodejs/node/pull/34864 Reviewed-By: Luigi Pinca --- lib/internal/blocklist.js | 4 ++++ test/parallel/test-blocklist.js | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/internal/blocklist.js b/lib/internal/blocklist.js index 0ad58373b746b2..28a31caa165e09 100644 --- a/lib/internal/blocklist.js +++ b/lib/internal/blocklist.js @@ -55,6 +55,7 @@ class BlockList { throw new ERR_INVALID_ARG_TYPE('address', 'string', address); if (typeof family !== 'string') throw new ERR_INVALID_ARG_TYPE('family', 'string', family); + family = family.toLowerCase(); if (family !== 'ipv4' && family !== 'ipv6') throw new ERR_INVALID_ARG_VALUE('family', family); const type = family === 'ipv4' ? AF_INET : AF_INET6; @@ -68,6 +69,7 @@ class BlockList { throw new ERR_INVALID_ARG_TYPE('end', 'string', end); if (typeof family !== 'string') throw new ERR_INVALID_ARG_TYPE('family', 'string', family); + family = family.toLowerCase(); if (family !== 'ipv4' && family !== 'ipv6') throw new ERR_INVALID_ARG_VALUE('family', family); const type = family === 'ipv4' ? AF_INET : AF_INET6; @@ -83,6 +85,7 @@ class BlockList { throw new ERR_INVALID_ARG_TYPE('prefix', 'number', prefix); if (typeof family !== 'string') throw new ERR_INVALID_ARG_TYPE('family', 'string', family); + family = family.toLowerCase(); let type; switch (family) { case 'ipv4': @@ -106,6 +109,7 @@ class BlockList { throw new ERR_INVALID_ARG_TYPE('address', 'string', address); if (typeof family !== 'string') throw new ERR_INVALID_ARG_TYPE('family', 'string', family); + family = family.toLowerCase(); if (family !== 'ipv4' && family !== 'ipv6') throw new ERR_INVALID_ARG_VALUE('family', family); const type = family === 'ipv4' ? AF_INET : AF_INET6; diff --git a/test/parallel/test-blocklist.js b/test/parallel/test-blocklist.js index cef90dc9a10e08..24f85e0f1b40f4 100644 --- a/test/parallel/test-blocklist.js +++ b/test/parallel/test-blocklist.js @@ -56,6 +56,7 @@ const assert = require('assert'); assert(blockList.check('8592:757c:efae:4e45:fb5d:d62a:0d00:8e17', 'ipv6')); assert(blockList.check('::ffff:1.1.1.1', 'ipv6')); + assert(blockList.check('::ffff:1.1.1.1', 'IPV6')); assert(blockList.check('1.1.1.2')); @@ -100,7 +101,7 @@ const assert = require('assert'); const blockList = new BlockList(); blockList.addAddress('1.1.1.1'); blockList.addRange('10.0.0.1', '10.0.0.10'); - blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6'); + blockList.addSubnet('8592:757c:efae:4e45::', 64, 'IpV6'); // Case insensitive const rulesCheck = [ 'Subnet: IPv6 8592:757c:efae:4e45::/64',