natesilva / is-in-subnet

Tests if an IPv4 or IPv6 address is in a given CIDR subnet

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't work for some IPv6 addresses

cbrunnkvist opened this issue · comments

> TRUSTED_ADDRESSES = ["127.0.0.1/8", "::1", "10.0.0.0/8", "fc00::/7"]
> isInSubnet('1.2.3.4', TRUSTED_ADDRESSES)

results in:

Error: not a valid IPv4 subnet: ::1
    at isInSubnet (./is-in-subnet/build/src/ipv4.js:35:15)

Ref: https://en.wikipedia.org/wiki/IPv6_address#Representation

Thank you. It wasn’t dealing with a mixed list of IPv4/IPv6 subnets. This will be fixed when I publish the next release today, but you’ll still need to specify a subnet: ::1/128 instead of just ::1.

Version 1.7.0 is released with this fix.