-
Notifications
You must be signed in to change notification settings - Fork 260
fix: NPM ipv6/CIDR validation #1401
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
Conversation
| ipDetails := strings.Split(ip, ",") | ||
| if util.IsIPV4(ipDetails[0]) { | ||
| return true | ||
| err := ValidateIPBlock(ipDetails[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we validate the whole ip like we used to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to change this because it would fail in the case of tcp since that method splits on a space and tcp has a comma. That method only validates CIDR so sending it already split seemed to make sense in this case
| } | ||
| } | ||
|
|
||
| func TestValidateIPSetMemberIP(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's put this code next to the other validate ip block tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
npm/util/util.go
Outdated
| ipOnly := strings.Split(ip, "/") | ||
| return net.ParseIP(ipOnly[0]).To4() != nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using the netip package (here but really everywhere)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
npm/util/util.go
Outdated
| _, _, err = net.ParseCIDR(ip) | ||
| return (err == nil && address.Is4()) | ||
| _, _, err2 := net.ParseCIDR(ip) | ||
| return (err == nil && err2 == nil && address.Is4()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check err where it is assigned and you don't have to avoid reassigning it and checking so many things here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, updated
* updated validation method and added unit tests * moved unit test * updated isIPV4 to use netip * fixed bool issue * fixed ipblock issue * refactored code * updated error handling * updated error handling
Reason for Change:
Issue Fixed:
Requirements:
Notes: