Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED JENKINS-48561] Give precedence to proxy exclusion list system property over env var #243

Merged
6 commits merged into from Mar 5, 2018
Expand Up @@ -26,6 +26,8 @@
import hudson.remoting.Base64;
import org.jenkinsci.remoting.util.https.NoCheckHostnameVerifier;
import org.jenkinsci.remoting.util.https.NoCheckTrustManager;
import sun.misc.RegexpPool;
import sun.net.NetProperties;

import java.io.IOException;
import java.net.ConnectException;
Expand Down Expand Up @@ -56,6 +58,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
Expand Down Expand Up @@ -377,7 +380,30 @@ static InetSocketAddress getResolvedHttpProxyAddress(@Nonnull String host, int p
while (targetAddress == null && proxies.hasNext()) {
Proxy proxy = proxies.next();
if (proxy.type() == Proxy.Type.DIRECT) {
break;
// Proxy.NO_PROXY with a DIRECT type is returned in two cases:
// - when no proxy (none) has been configured in the JVM (either with system properties or by the operating system)
// - when the URI host is part of the exclusion list defined by system property -Dhttp.nonProxyHosts
//
// Unfortunately, the Proxy class does not provide a way to differentiate both cases to fallback to
// environment variables only when no proxy has been configured. Therefore, we have to recheck if the URI
// host is in the exclusion list.
String nonProxyHosts = NetProperties.get("http.nonProxyHosts");
if(nonProxyHosts != null && nonProxyHosts.length() != 0) {
RegexpPool exclusionsPool = new RegexpPool();
StringTokenizer stringTokenizer = new StringTokenizer(nonProxyHosts, "|", false);
try {
while(stringTokenizer.hasMoreTokens()) {
exclusionsPool.add(stringTokenizer.nextToken().toLowerCase(), Boolean.TRUE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toLowerCase() is invoked without locale, it will cause FindBugs failures with #242 I'd guess

}
} catch(sun.misc.REException e) {
System.err.println("Malformed exception list in http.nonProxyHosts system property: " + e.getMessage());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will need to rework everything to loggers

}
if(exclusionsPool.match(host.toLowerCase()) != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

locale

return null;
} else {
break;
}
}
}
if (proxy.type() == Proxy.Type.HTTP) {
final SocketAddress address = proxy.address();
Expand Down