Skip to content

Commit

Permalink
net: make blocklist family case insensitive
Browse files Browse the repository at this point in the history
Signed-off-by: James M Snell <[email protected]>

PR-URL: #34864
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
jasnell authored and MylesBorins committed Aug 31, 2021
1 parent 85af15a commit a41a3e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/internal/blocklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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':
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-blocklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit a41a3e3

Please sign in to comment.