Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-2061

IP address filter with netmask not working as expected

    XMLWordPrintable

Details

    • Hide
      • Configure an ip address filter with a netmask e.g. "85.112.112.58/29 allow"
      • Try to connect from the ip address 85.112.112.58 => access is denied

      Or in add this test to IPAddressAccessControlHandlerUnitTestCase.java

          @Test
          public void testIPv4SlashMatchDefaultDeny() throws UnknownHostException {
              IPAddressAccessControlHandler handler = new IPAddressAccessControlHandler()
                      .setDefaultAllow(false)
                      .addAllow("85.112.112.58/29");
              Assert.assertTrue(handler.isAllowed(InetAddress.getByName("85.112.112.58")));
          }
      
      
      Show
      Configure an ip address filter with a netmask e.g. "85.112.112.58/29 allow" Try to connect from the ip address 85.112.112.58 => access is denied Or in add this test to IPAddressAccessControlHandlerUnitTestCase.java @Test public void testIPv4SlashMatchDefaultDeny() throws UnknownHostException { IPAddressAccessControlHandler handler = new IPAddressAccessControlHandler() .setDefaultAllow( false ) .addAllow( "85.112.112.58/29" ); Assert.assertTrue(handler.isAllowed(InetAddress.getByName( "85.112.112.58" ))); }
    • Workaround Exists
    • Hide

      Instead of configuring ip-address/mask one can pass an adjusted ip address with the mask already applied, .e.g:

      Original setting

      85.112.112.58/29 

      IP address in binary: 01010101 01110000 01110000 001110 1 0

      Workaround setting

      85.112.112.56/29

      IP address in binary: 01010101 01110000 01110000 001110 0 0

      Binary netmask is 11111111 11111111 11111111 11111000 in both cases

      Show
      Instead of configuring ip-address/mask one can pass an adjusted ip address with the mask already applied, .e.g: Original setting 85.112.112. 58 /29   IP address in binary: 01010101 01110000 01110000 001110 1 0 Workaround setting 85.112.112. 56 /29 IP address in binary: 01010101 01110000 01110000 001110 0 0 Binary netmask is 11111111 11111111 11111111 11111000 in both cases

    Description

      When configuring an ip address filter with netmask it may not work as expected.

      In our case we configured an ip address filter to allow specific IPs to access special URLs in our keycloak instances - but access was still denied.

      We could nail down the issue to the undertow source code.

      Maybe this could be solved by adding just one line to IPAddressAccessControlHandler.java:

       private void addIpV4SlashPrefix(final String peer, final boolean deny) {
              String[] components = peer.split("\\/");
              String[] parts = components[0].split("\\.");
              int maskLen = Integer.parseInt(components[1]);
              final int mask = Bits.intBitMask(32 - maskLen, 31);
              int prefix = 0;
              for (int i = 0; i < 4; ++i) {
                  prefix <<= 8;
                  String part = parts[i];
                  int no = Integer.parseInt(part);
                  prefix |= no;
              }
              prefix &= mask; // <-- adding this line fixes the tests
              ipv4acl.add(new PrefixIpV4PeerMatch(deny, peer, mask, prefix));
          }
      

      Attachments

        Issue Links

          Activity

            People

              rhn-cservice-bbaranow Bartosz Baranowski
              ioemat Jörg Matysiak
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: