Skip to content

BlockList addRange appears to match addresses incorrectly #39074

@EricHripko

Description

@EricHripko
  • Version: v16.3.0
  • Platform: Darwin <redacted> 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:41 PDT 2021; root:xnu-7195.101.2~1/RELEASE_ARM64_T8101 arm64
  • Subsystem: net

What steps will reproduce the bug?

I've used the following code snippet from Node.JS Net docs to try to block IPs based on ranges:

> const blockList = new net.BlockList();
undefined
> blockList.addRange('10.0.0.1', '10.0.0.10');
undefined
> blockList.check('10.0.0.3')
true
> blockList.check('192.168.0.3')
true

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

Always reproduces.

What is the expected behavior?

I expect the block list with above-mentioned configuration to block 10.0.0.3 but allow 192.168.0.3 (i.e., check to return false).

What do you see instead?

It looks as if BlockList matches only the last element of the IP address. As a result, check returns true for 192.168.0.3 even though it's not in the range:

> blockList.rules
[ 'Range: IPv4 10.0.0.1-10.0.0.10' ]

Additional information

addAddress and (more importantly) addSubnet appears to work fine:

> const blockList = new net.BlockList(); 
undefined
> blockList.addSubnet("10.0.0.0", 29)  # 10.0.0.0/29 = 10.0.0.0-10.0.0.7
undefined
> blockList.check('10.0.0.3')
true
> blockList.check('192.168.0.3')
false

Metadata

Metadata

Assignees

No one assigned

    Labels

    netIssues and PRs related to the net subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions