Skip to content

Commit 539c715

Browse files
net: prevent /32 ipv4 mask from matching all ips
Fixes: #43360
1 parent 3987d6b commit 539c715

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/node_sockaddr.cc

+3
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ bool in_network_ipv4(
215215
const SocketAddress& ip,
216216
const SocketAddress& net,
217217
int prefix) {
218+
if (prefix == 32)
219+
return compare_ipv4(ip, net) == SocketAddress::CompareResult::SAME;
220+
218221
uint32_t mask = ((1 << prefix) - 1) << (32 - prefix);
219222

220223
const sockaddr_in* ip_in =

test/parallel/test-blocklist.js

+10
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,13 @@ const util = require('util');
272272
const ret = util.inspect(blockList, { depth: null });
273273
assert(ret.includes('rules: []'));
274274
}
275+
276+
{
277+
// Test for https://github.com/nodejs/node/issues/43360
278+
const blocklist = new BlockList();
279+
blocklist.addSubnet('1.1.1.1', 32, 'ipv4');
280+
281+
assert(blocklist.check('1.1.1.1'));
282+
assert(!blocklist.check('1.1.1.2'));
283+
assert(!blocklist.check('2.3.4.5'));
284+
}

0 commit comments

Comments
 (0)