xubenqiang opened a new pull request, #11591:
URL: https://github.com/apache/rocketmq/pull/11591
Fixes #11558
## Problem
`IPAddressUtils.isValidIPv4Cidr` / `isValidIPv6Cidr` parse the network part
with `InetAddress.getByName`, which performs name resolution (and maps an empty
string to `127.0.0.1`). As a result:
- `isValidCidr("/24")` and `isValidCidr("localhost/24")` return `true`;
- since ACL validation uses `isValidIPOrCidr` for the source-IP whitelist,
such invalid entries are accepted.
## Change
Validate the network part with the existing `InetAddressValidator` (literal
parsing, no DNS):
```java
String[] parts = cidr.split(SLASH, -1);
if (parts.length != 2 || !VALIDATOR.isValidInet4Address(parts[0])) {
return false;
}
```
Same for the IPv6 variant. The `split("/", -1)` also keeps empty trailing
segments so `"1.2.3.4/"` stays rejected.
## Tests
Added `isValidCidrRejectsNonLiteralNetworkParts` to `IPAddressUtilsTest`
covering `/24`, `localhost/24`, `example.com/24`, out-of-range prefixes, and
the valid boundaries (`127.0.0.1/32`, `::1/128`).
Before the fix (test kept, production change reverted):
```
Tests run: 6, Failures: 1, Errors: 0, Skipped: 1
isValidCidrRejectsNonLiteralNetworkParts ... FAILURE
```
After:
```
mvn -q -pl common -am test -Dtest=IPAddressUtilsTest
-Dsurefire.failIfNoSpecifiedTests=false
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0
exit 0
```
## AI assistance
Written with an AI coding assistant; the reproduction, fix and both test
runs above were executed locally.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]