JDK-8025065 : "Bypass proxy server for local addresses" not taken into account
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • Submitted: 2013-09-11
  • Updated: 2022-01-21
  • Resolved: 2022-01-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
Java 1.7.0_25

ADDITIONAL OS VERSION INFORMATION :
Windows 7 64-bit

A DESCRIPTION OF THE PROBLEM :
When you set up a proxy server (Internet Options->LAN Settings) in Windows 7 there is a checkbox called:

"Bypass proxy server for local addresses"

This means that HTTP connections to "localhost" or "127.0.0.1" should avoid going through the server.
This no longer happens, it used to work with Java 1.6 but in Java 1.7 the proxy is used also for localhost connections, probably this issue introduced the problem:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6737819

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Call this code:

    System.setProperty("java.net.useSystemProxies", "true");
    System.err.println(ProxySelector.getDefault().select(new URI("http://localhost/index.html")));
    System.err.println(ProxySelector.getDefault().select(new URI("http://127.0.0.1/index.html")));
    System.err.println(ProxySelector.getDefault().select(new URI("http://www.oxygenxml.com/index.html")));

The code should return a direct PROXY connection for the first two URIs and the proxy configured in the system for the third one (because the "Bypass proxy server for local addresses" checkbox is checked).

But it returns the same configured proxy for all connections.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should return a direct PROXY connection for the first two URIs and the proxy configured in the system for the third one (because the "Bypass proxy server for local addresses" checkbox is checked).
ACTUAL -
But it returns the same configured proxy for all connections.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
    System.setProperty("java.net.useSystemProxies", "true");
    System.err.println(ProxySelector.getDefault().select(new URI("http://localhost/index.html")));
    System.err.println(ProxySelector.getDefault().select(new URI("http://127.0.0.1/index.html")));
    System.err.println(ProxySelector.getDefault().select(new URI("http://www.oxygenxml.com/index.html")));
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I can set my own proxy configuration in the system which wraps the current one and returns a direct proxy for localhost connections.
Comments
Proxy selection was reimplemented in JDK-8170868. Bypassing proxy for local addresses now works as described in https://docs.microsoft.com/en-us/troubleshoot/developer/browsers/connectivity-navigation/internet-explorer-uses-proxy-server-local-ip-address, i.e. proxy is bypassed when connecting to a hostname, and is not bypassed when connecting to an IP address or a FQDN.
21-01-2022

Chris, looks like the code that is responsible for this thing indeed doesn't take this "Bypass proxy server for local addresses" checkbox into account. Although sun.net.spi.DefaultProxySelector respects the 'java.net.useSystemProxies' property it doesn't handle it correctly especially in conjunction with "Bypass proxy server for local addresses". The DefaultProxySelector asks Windows registry for a proxy data and makes all decisions by itself rather than tells Windows a URL and gets the connection parameters back. This checkbox appends a '<local>' literal to the list of ';' separated proxy exceptions. There are two problems with it: 1. '<local>' is never interpreted right since the DefaultProxySelector tries to match it against host the URL is referring to. But that's not a host literal, this is a marker value. 2. Looks like "Bypass proxy server for local addresses" doesn't mean what we might think it means [1] (the Microsoft documentation [2,3] on this is pretty vague). Keeping all that in mind I think we have at least following options: 1. Add special treatment for '<local>' literal (i.e. duplicate some Windows logic in DefaultProxySelector) 2. Try to use (are they applicable here?) WinINet or WinHTTP APIs [4,5] to tell OS to do its magic and to figure out connection parameters for a given URL for us. The first option requires (in my opinion) some refactoring to bring C layer string manipulation code to the Java layer. The second option requires more investigation. Who knows it might work only with HTTP protocol or have some additional restrictions. -------------------------------------------------------------------------------- [1] http://www.windowsreference.com/internet-explorer/bypass-proxy-server-for-local-addresses-in-internet-explorer-explained/ [2] http://technet.microsoft.com/en-us/library/gg598613.aspx [3] http://windows.microsoft.com/en-us/windows-vista/changing-intranet-security-settings [4] http://msdn.microsoft.com/en-us/library/windows/desktop/hh227297(v=vs.85).aspx [5] http://msdn.microsoft.com/en-us/library/windows/desktop/aa384097(v=vs.85).aspx
23-04-2014

At a very minimum would it make sense for the ProxyOverride value of '<local>' to be special cased ( option 1 above ), and have it match a limited set of known localhost|127.* ??
23-04-2014

Pavel, could you take a look at this and see if it is still relevant?
10-04-2014