Skip to content

/32 subnet mask erroneously matches all IP addresses #43360

Closed
@supriyo-biswas

Description

@supriyo-biswas

Version

v18.3.0

Platform

Darwin xxx 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64

Subsystem

net

What steps will reproduce the bug?

A /32 subnet mask such as 1.1.1.1/32 should match only the IP address 1.1.1.1 as all 32 bits should be compared. However, if a /32 subnet mask is used with net.Blocklist(), it erroneously matches all IP addresses.

The issue can be reproduced by running the following code snippet:

const net = require('net')

const reservedIPBlocklist = new net.BlockList()
reservedIPBlocklist.addSubnet('1.1.1.1', 32, 'ipv4')

for (const ip of ["10.0.0.1", "1.1.1.1", "4.3.2.4", "27.192.11.1", 
"192.168.1.9"]) {
    console.log(ip, reservedIPBlocklist.check(ip, 'ipv4'))    
}

Even though only 1.1.1.1 should match, true is printed for all the IPs:

10.0.0.1 true
1.1.1.1 true
4.3.2.4 true
27.192.11.1 true
192.168.1.9 true

If the subnet mask is changed to < 32, Node behaves correctly.

How often does it reproduce? Is there a required condition?

The bug can always be reproduced.

What is the expected behavior?

See above.

What do you see instead?

See above.

Additional information

This bug is present across other versions of Node too, for example see https://www.mycompiler.io/view/1JuZ56bnWhl where the Node version is Node 16.15.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.good first issueIssues that are suitable for first-time contributors.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions