leaveWhite9088 opened a new issue, #11530: URL: https://github.com/apache/rocketmq/issues/11530
### Before Creating the Bug Report - [x] I found a bug, not just asking a question, which should be created in [GitHub Discussions](https://github.com/apache/rocketmq/discussions). - [x] I have searched the [GitHub Issues](https://github.com/apache/rocketmq/issues) and [GitHub Discussions](https://github.com/apache/rocketmq/discussions) of this repository and believe that this is not a duplicate. - [x] I have confirmed that this bug belongs to the current repository, not other repositories of RocketMQ. ### Runtime platform environment OS: Windows 11 (platform-independent logic bug in `rocketmq-common`) ### RocketMQ version - branch: `develop` - version: `5.5.1` - Git commit id: `cb0dfc2ea` ### JDK Version Eclipse Temurin JDK 11.0.33 ### Describe the Bug `IPAddressUtils.isIPInRange(String ip, String cidr)` in `common/src/main/java/org/apache/rocketmq/common/utils/IPAddressUtils.java` converts both `cidrIp.getAddress()` and `InetAddress.getByName(ip).getAddress()` directly into unsigned `BigInteger` values without verifying that both addresses belong to the same address family (byte length `4` for IPv4 vs `16` for IPv6), and without validating that `prefixLength` is within `[0, maxPrefixLength]`. As a result: 1. **Cross-family CIDR matching bypass**: - `IPAddressUtils.isIPInRange("192.168.1.10", "::/64")` returns `true` (every IPv4 address numerically falls in `[0, 2^64 - 1]`). - `IPAddressUtils.isIPInRange("0.0.0.1", "::1/128")` returns `true`. - `IPAddressUtils.isIPInRange("::1", "0.0.0.0/0")` returns `true`. - Because `Environment#isMatch` in `rocketmq-auth` delegates source IP policy matching to `IPAddressUtils.isIPInRange`, an authorization policy configured with an IPv6 CIDR such as `::/64` unintentionally matches all IPv4 client addresses. 2. **Out-of-range prefix length**: - Inputs such as `"192.168.1.0/33"`, `"192.168.1.0/-1"`, or `"::/129"` compute a negative shift count in `BigInteger.valueOf(-1).shiftLeft(cidrBytes.length * 8 - prefixLength)` instead of returning `false`. 3. **Null/blank inputs**: - `isIPInRange(null, null)` returns `true` via `StringUtils.equals(null, null)` on the single-IP path. ### Steps to Reproduce Call `IPAddressUtils.isIPInRange`: ```java IPAddressUtils.isIPInRange("192.168.1.10", "::/64"); // returns true IPAddressUtils.isIPInRange("0.0.0.1", "::1/128"); // returns true IPAddressUtils.isIPInRange("::1", "0.0.0.0/0"); // returns true IPAddressUtils.isIPInRange("192.168.1.10", "192.168.1.0/33"); // does not reject invalid prefix IPAddressUtils.isIPInRange(null, null); // returns true ``` ### What Did You Expect to See? - Cross-family IP/CIDR checks (IPv4 address against IPv6 CIDR, or IPv6 address against IPv4 CIDR) should return `false`. - Invalid CIDR prefix lengths (`< 0` or `> 32` for IPv4, `> 128` for IPv6) should return `false`. - Null or blank inputs should return `false`. ### What Did You See Instead? Cross-family IP/CIDR checks and `isIPInRange(null, null)` return `true`. ### Additional Context I have verified the reproduction with a unit test in `IPAddressUtilsTest` and will submit a PR to fix this. -- 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]
