Skip to content

Commit 37a8179

Browse files
jasnellnodejs-github-bot
authored andcommitted
net: make blocklist family case insensitive
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #34864 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent a996df6 commit 37a8179

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/internal/blocklist.js

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class BlockList {
5555
throw new ERR_INVALID_ARG_TYPE('address', 'string', address);
5656
if (typeof family !== 'string')
5757
throw new ERR_INVALID_ARG_TYPE('family', 'string', family);
58+
family = family.toLowerCase();
5859
if (family !== 'ipv4' && family !== 'ipv6')
5960
throw new ERR_INVALID_ARG_VALUE('family', family);
6061
const type = family === 'ipv4' ? AF_INET : AF_INET6;
@@ -68,6 +69,7 @@ class BlockList {
6869
throw new ERR_INVALID_ARG_TYPE('end', 'string', end);
6970
if (typeof family !== 'string')
7071
throw new ERR_INVALID_ARG_TYPE('family', 'string', family);
72+
family = family.toLowerCase();
7173
if (family !== 'ipv4' && family !== 'ipv6')
7274
throw new ERR_INVALID_ARG_VALUE('family', family);
7375
const type = family === 'ipv4' ? AF_INET : AF_INET6;
@@ -83,6 +85,7 @@ class BlockList {
8385
throw new ERR_INVALID_ARG_TYPE('prefix', 'number', prefix);
8486
if (typeof family !== 'string')
8587
throw new ERR_INVALID_ARG_TYPE('family', 'string', family);
88+
family = family.toLowerCase();
8689
let type;
8790
switch (family) {
8891
case 'ipv4':
@@ -106,6 +109,7 @@ class BlockList {
106109
throw new ERR_INVALID_ARG_TYPE('address', 'string', address);
107110
if (typeof family !== 'string')
108111
throw new ERR_INVALID_ARG_TYPE('family', 'string', family);
112+
family = family.toLowerCase();
109113
if (family !== 'ipv4' && family !== 'ipv6')
110114
throw new ERR_INVALID_ARG_VALUE('family', family);
111115
const type = family === 'ipv4' ? AF_INET : AF_INET6;

test/parallel/test-blocklist.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const assert = require('assert');
5656
assert(blockList.check('8592:757c:efae:4e45:fb5d:d62a:0d00:8e17', 'ipv6'));
5757

5858
assert(blockList.check('::ffff:1.1.1.1', 'ipv6'));
59+
assert(blockList.check('::ffff:1.1.1.1', 'IPV6'));
5960

6061
assert(blockList.check('1.1.1.2'));
6162

@@ -100,7 +101,7 @@ const assert = require('assert');
100101
const blockList = new BlockList();
101102
blockList.addAddress('1.1.1.1');
102103
blockList.addRange('10.0.0.1', '10.0.0.10');
103-
blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');
104+
blockList.addSubnet('8592:757c:efae:4e45::', 64, 'IpV6'); // Case insensitive
104105

105106
const rulesCheck = [
106107
'Subnet: IPv6 8592:757c:efae:4e45::/64',

0 commit comments

Comments
 (0)