orangehedgehog3 opened a new issue, #11558:
URL: https://github.com/apache/rocketmq/issues/11558

   ### 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
   
   ### RocketMQ version
   
   branch: develop
   version: 5.5.1
   Git commit id: 28960fd2f795a6903665c3d6c037501059df0760
   
   ### JDK Version
   
   Compiler: Temurin JDK 1.8.0_504
   OS: Windows 11
   
   ### Describe the Bug
   
   IPAddressUtils#isValidIPv4Cidr and #isValidIPv6Cidr parse the network part 
of a CIDR with
   InetAddress.getByName. That method resolves host names and returns 127.0.0.1 
for an empty
   string, so inputs that are not IP literals are treated as valid CIDRs.
   
   As a result, isValidCidr("/24") and isValidCidr("localhost/24") both return 
true.
   isValidIPOrCidr is used by ACL validation 
(AuthorizationMetadataManagerImpl#validate) for
   the source IP whitelist, so such invalid entries are accepted instead of 
being rejected.
   
   The network part of a CIDR should be a literal IP of the matching address 
family, and no
   name resolution should happen during validation.
   
   ### Steps to Reproduce
   
   1. Add the following test to
      
common/src/test/java/org/apache/rocketmq/common/utils/IPAddressUtilsTest.java:
   
      @Test
      public void reproduce() {
          Assert.assertFalse(IPAddressUtils.isValidCidr("/24"));
          Assert.assertFalse(IPAddressUtils.isValidCidr("localhost/24"));
      }
   
   2. Run: mvn -pl common -Dtest=IPAddressUtilsTest test
   3. Both assertions fail because both calls return true.
   
   ### What Did You Expect to See?
   
   isValidCidr("/24") and isValidCidr("localhost/24") should return false.
   Only literal IPv4/IPv6 addresses with a valid prefix length should be 
accepted.
   
   ### What Did You See Instead?
   
   Both calls return true:
   - InetAddress.getByName("") returns 127.0.0.1 (4 bytes), so "/24" passes the 
IPv4 check.
   - InetAddress.getByName("localhost") resolves to 127.0.0.1, so 
"localhost/24" also passes.
   
   ### Additional Context
   
   Related but not duplicate: #11530 / #11531 hardened 
IPAddressUtils#isIPInRange.
   
   I already have a small fix prepared (validate the network part with 
isValidIPv4 /
   isValidIPv6 and add unit tests) and I am willing to submit a PR.


-- 
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]

Reply via email to