diff --git a/dependency-check-maven/src/main/java/org/owasp/dependencycheck/maven/BaseDependencyCheckMojo.java b/dependency-check-maven/src/main/java/org/owasp/dependencycheck/maven/BaseDependencyCheckMojo.java index b2c005199..c6ff64a13 100644 --- a/dependency-check-maven/src/main/java/org/owasp/dependencycheck/maven/BaseDependencyCheckMojo.java +++ b/dependency-check-maven/src/main/java/org/owasp/dependencycheck/maven/BaseDependencyCheckMojo.java @@ -667,6 +667,7 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma final String password = proxy.getPassword(); Settings.setStringIfNotNull(Settings.KEYS.PROXY_USERNAME, userName); Settings.setStringIfNotNull(Settings.KEYS.PROXY_PASSWORD, password); + Settings.setStringIfNotNull(Settings.KEYS.PROXY_NON_PROXY_HOSTS, proxy.getNonProxyHosts()); } Settings.setStringIfNotEmpty(Settings.KEYS.CONNECTION_TIMEOUT, connectionTimeout); diff --git a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java index 2cabc9b87..1ef117eb8 100644 --- a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java +++ b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java @@ -165,6 +165,10 @@ public final class Settings { * The properties key for the proxy password. */ public static final String PROXY_PASSWORD = "proxy.password"; + /** + * The properties key for the non proxy hosts. + */ + public static final String PROXY_NON_PROXY_HOSTS = "proxy.nonproxyhosts"; /** * The properties key for the connection timeout. */ diff --git a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java index c11e3ecf9..b949d07ec 100644 --- a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java +++ b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java @@ -53,13 +53,15 @@ public final class URLConnectionFactory { public static HttpURLConnection createHttpURLConnection(URL url) throws URLConnectionFailureException { HttpURLConnection conn = null; final String proxyUrl = Settings.getString(Settings.KEYS.PROXY_SERVER); + try { - if (proxyUrl != null) { + if (proxyUrl != null && !skipProxy(url)) { final int proxyPort = Settings.getInt(Settings.KEYS.PROXY_PORT); final SocketAddress address = new InetSocketAddress(proxyUrl, proxyPort); final String username = Settings.getString(Settings.KEYS.PROXY_USERNAME); final String password = Settings.getString(Settings.KEYS.PROXY_PASSWORD); + if (username != null && password != null) { final Authenticator auth = new Authenticator() { @Override @@ -94,6 +96,24 @@ public final class URLConnectionFactory { return conn; } + /** + * Checks of for the given URL the proxy shall be used or not checking the nonProxyHosts configuration. + * @param url The URL to check. + * @return If the proxy shall be skip for the given URL or not. + */ + private static boolean skipProxy(URL url) { + boolean skip = false; + final String nonProxySettings = Settings.getString(Settings.KEYS.PROXY_NON_PROXY_HOSTS); + String[] nonProxyHosts = nonProxySettings.split(","); + for (int i = 0; i < nonProxyHosts.length; i++) { + if (url.getHost().matches(nonProxyHosts[i])) { + skip = true; + break; + } + } + return skip; + } + /** * Utility method to create an HttpURLConnection. The use of a proxy here is optional as there may be cases where a proxy is * configured but we don't want to use it (for example, if there's an internal repository configured)