Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not validating properly (IPV4 with block >= 256 still returns true) #105

Open
nolawnchairs opened this issue Aug 25, 2020 · 1 comment
Open

Comments

@nolawnchairs
Copy link

Hi,

The methods ip.isV4Format() and ip.isV6Format() are returning true for an invalid IP address:

const ipAddress = "103.23.133.256";
console.log(ipAddress, ip.isV4Format(ipAddress), ip.isV6Format(ipAddress));
// > 103.23.133.256 true true

Should this not validate each block so that V4 blocks > 255 would case the function to return false? Also, since V4 and V6 addresses have different delimiters (colons/periods) that passing a V4 address into the isV6Format function should return false as well?

Would it be possible to add a validation method that accepts both V4 and V6 addresses and validates them?

@slavikme
Copy link

slavikme commented Jun 5, 2024

You are right, this should return false. Seems like a buggy implementation.

Anyway, you could verify it using this method:

function isValidIPv4 (address) {
  return ip.isV4Format(address) && ip.cidr(address+'/32') === address
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants