Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8289514

ProxySelector should support Chromium's implicit bypass rules

XMLWordPrintable

    • generic
    • windows

      See definition:
      https://chromium.googlesource.com/chromium/src/+/HEAD/net/docs/proxy.md#Implicit-bypass-rules

      Bypass rule:
      https://chromium.googlesource.com/chromium/src/+/HEAD/net/docs/proxy.md#bypass-rule_subtract-implicit-rules

      Original bug report:

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 21H2
      OpenJDK 17.0.3


      A DESCRIPTION OF THE PROBLEM :
      When trying to open a socket connection to 127.0.0.1 with the java.net.useSystemProxies enabled - the "do not use proxy server for local addresses" setting is not respected. For 127.0.0.1 the configured proxy will get packed up, even though 127.0.0.1 is the loopback interface.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - setting the java.net.useSystemProxies to true
      - disabling the automatically detect proxy settings and setting up a manual proxy configuration with "do not use proxy server for local addresses" checked
      - Open a socket connection to 127.0.0.1


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      as 127.0.0.1 is the loopback local address, the DICRECT proxy should be used
      ACTUAL -
      The proxy which is configured in Windows settings is selected

      ---------- BEGIN SOURCE ----------
      import java.io.IOException;
      import java.net.InetSocketAddress;
      import java.net.ServerSocket;
      import java.net.Socket;

      class Reproducer
      {
        public static void main(String[] args) throws InterruptedException
        {
          System.setProperty("java.net.useSystemProxies", "true");
          final int port = 54434;
          Thread server = serverThread(port);
          Thread client = clientThread(port);
          server.start();
          client.start();
          server.join();
          client.join();
        }

        private static Thread serverThread(int port)
        {
          return new Thread(() -> {
              try (ServerSocket serverSocket = new ServerSocket())
              {
                serverSocket.bind(new InetSocketAddress(port));
                serverSocket.accept();
                System.out.println("Got connection from socket, exit.");
              }
            catch (IOException e)
            {
              throw new RuntimeException(e);
            }
          });
        }

        private static Thread clientThread(int port) {
          return new Thread(() -> {
            try (Socket socket = new Socket())
            {
              //using "localhost" here will work
              socket.connect(new InetSocketAddress("127.0.0.1", port), 2500);
            }
            catch (IOException e)
            {
              //should be able to connect, but will fail with connection refused due to proxy
              e.printStackTrace();
              System.exit(1);
            }
          });
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use "localhost" as the host for the socket connection, seems that the proxy determining code just checks if the host string contains "." to determine if it's a remote address or not.

      FREQUENCY : always


            djelinski Daniel Jelinski
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: