whitequark / ipaddr.js

IP address manipulation library in JavaScript
MIT License
570 stars 92 forks source link

Internal Error when authenticating request to /evolvi: ipaddr: cannot match ipv6 address with non-ipv6 one #165

Open hardysabs2 opened 2 years ago

hardysabs2 commented 2 years ago

Hi,

I am retrieving client ip(s) on an incoming request, from the header (x-forwarded-for) or from other request attribute(s).

I think I do not necessarily know if these will present as ipv6 or ipv4. However I have a set of valid ipv4 client addresses and a set of ipv4 CIDRs I am required to filter/authenticate against.

A straight match is easy to do check if any of each valid ipv4 addresses is included within incoming request client ip.

However when I try var clientAddr = ipaddr.parse(clientIP.trim()); clientAddr.match(ipaddr.parseCIDR(validCIDR));

where validCIDR is always of the example form 111.111.111.144/29 , but clientIP may be of the example form "::ffff:127.0.0.1" or "127.0.0.1". I don't thin I can be sure.

What is the best way to account for this?