@Test public void isPrivate() { String[] privateUrls = new String[]{ "http: "http: "http: "http: "http: "http: "http: "https: "http: "http: "http: "http: "http: "http: }; for (String url : privateUrls) { assertTrue("Url [" + url + "] should be considered private", UrlSanitizerUtils.isPrivate(url)); } }
public static boolean isPrivate(String url) { try { InetAddress inetAddress = Inet6Address.getByName(new URL(url).getHost()); return inetAddress.isSiteLocalAddress() || inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isLinkLocalAddress() || inetAddress.isMulticastAddress() || isPrivateOwasp(inetAddress.getHostAddress()); } catch (Exception e) { throw new InvalidDataException("Url [" + url + "] is invalid"); } }
UrlSanitizerUtils { public static boolean isPrivate(String url) { try { InetAddress inetAddress = Inet6Address.getByName(new URL(url).getHost()); return inetAddress.isSiteLocalAddress() || inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isLinkLocalAddress() || inetAddress.isMulticastAddress() || isPrivateOwasp(inetAddress.getHostAddress()); } catch (Exception e) { throw new InvalidDataException("Url [" + url + "] is invalid"); } } }
UrlSanitizerUtils { public static boolean isPrivate(String url) { try { InetAddress inetAddress = Inet6Address.getByName(new URL(url).getHost()); return inetAddress.isSiteLocalAddress() || inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isLinkLocalAddress() || inetAddress.isMulticastAddress() || isPrivateOwasp(inetAddress.getHostAddress()); } catch (Exception e) { throw new InvalidDataException("Url [" + url + "] is invalid"); } }  }
UrlSanitizerUtils { public static boolean isPrivate(String url) { try { InetAddress inetAddress = Inet6Address.getByName(new URL(url).getHost()); return inetAddress.isSiteLocalAddress() || inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isLinkLocalAddress() || inetAddress.isMulticastAddress() || isPrivateOwasp(inetAddress.getHostAddress()); } catch (Exception e) { throw new InvalidDataException("Url [" + url + "] is invalid"); } }  static void checkAllowed(String url, List<String> whitelist, boolean allowPrivate); static boolean isPrivate(String url); }
UrlSanitizerUtils { public static boolean isPrivate(String url) { try { InetAddress inetAddress = Inet6Address.getByName(new URL(url).getHost()); return inetAddress.isSiteLocalAddress() || inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isLinkLocalAddress() || inetAddress.isMulticastAddress() || isPrivateOwasp(inetAddress.getHostAddress()); } catch (Exception e) { throw new InvalidDataException("Url [" + url + "] is invalid"); } }  static void checkAllowed(String url, List<String> whitelist, boolean allowPrivate); static boolean isPrivate(String url);  }