shared/validate: reject descending IPv4 and IPv6 ranges#18331
Merged
tomponline merged 1 commit intoMay 26, 2026
Conversation
Signed-off-by: immanuwell <pchpr.00@list.ru>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens the shared/validate IPv4/IPv6 range validators so they reject descending IP ranges (e.g. 10.0.0.10-10.0.0.1), aligning their behavior with downstream range parsing/usage.
Changes:
- Update
IsNetworkRangeV4andIsNetworkRangeV6to also enforce start/end ordering by delegating toIsNetworkRangeafter validating address family. - Add unit tests covering valid, descending, wrong-family, and non-range inputs for both IPv4 and IPv6 range validators.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| shared/validate/validate.go | Ensures IPv4/IPv6 range validators reject descending ranges by reusing the shared ordering/family checks in IsNetworkRange. |
| shared/validate/validate_test.go | Adds targeted tests for IsNetworkRangeV4 and IsNetworkRangeV6 to confirm descending ranges and invalid formats are rejected. |
simondeziel
approved these changes
May 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This tightens
IsNetworkRangeV4andIsNetworkRangeV6so they reject descending ranges too.Right now they can accept stuff like
10.0.0.10-10.0.0.1or2001:db8::10-2001:db8::1, which is kinda bogus. Downstream parsing rejects the same input later, so this is a small validation hole and a tiny footgun.Repro
Before this patch:
But the same ranges fail once parsed for actual use:
So yeah, same bad input, two different answers. This patch makes the first check stop lying a bit.
Tests
go test ./shared/validate