multiformats/js-multiaddr

Invalid ipv4 address are converted to valid ones

Closed this issue · 4 comments

Summary: The ipv4 regex here is what node-ip uses to verify valid ip address format, this logic is being used to validate ip addresses , and right now an invalid address 555.555.555.55 will be converted to a valid address and return 43.43.43.55.

Proposal: I think ideally it would make sense that the regex within the ip-node package were fixed, however the project seems like it hasn't been touched in the past year. Alternatively I think it might make sense to just wrap the calls here and here with a regex check and throw an error just like the package would in the event of an ascii character in the ip address.

vmx commented

As it looks like an upstream fix won't be merged soon, wrapping it directly makes sense. If you add the additional check, how hard would it be to also do an upstream patch? I'm always in favour of fixing upstream bugs as well.

I think it would be really simple its really just changing the regex within ip-node, I'll file a PR in both places 🤞 if the upstream lands :)

Wrote the patch for ipv4 and realized ipv6 validations are also incorrect. Ipv6 validation is a little more complex, I'm not yet convinced that ip-node does the right thing, even if I patch the first issue that I've spotted with ipv6. It might be a decent idea to use a different package for translating the ipv6 string to a buffer. This seems fairly complete, downside here is that it's coffeescript and might not be a package that belongs within the ecosystem.

Fixed with #60