|
@@ -42,6 +42,7 @@ import java.net.Socket;
|
|
|
import java.net.SocketAddress;
|
|
|
import java.net.SocketImplFactory;
|
|
|
import java.net.URI;
|
|
|
+import java.net.URISyntaxException;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLStreamHandler;
|
|
|
import java.net.URLStreamHandlerFactory;
|
|
@@ -67,6 +68,7 @@ import java.nio.file.Files;
|
|
|
import java.nio.file.LinkOption;
|
|
|
import java.nio.file.OpenOption;
|
|
|
import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.nio.file.StandardOpenOption;
|
|
|
import java.nio.file.WatchEvent;
|
|
|
import java.nio.file.WatchService;
|
|
@@ -636,6 +638,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$java_net_URL$openConnection(Class<?> callerClass, java.net.URL that) {
|
|
|
if (isNetworkUrl(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrl(that)) {
|
|
|
+ checkURLFileRead(callerClass, that);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -643,6 +647,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$java_net_URL$openConnection(Class<?> callerClass, URL that, Proxy proxy) {
|
|
|
if (proxy.type() != Proxy.Type.DIRECT || isNetworkUrl(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrl(that)) {
|
|
|
+ checkURLFileRead(callerClass, that);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -650,6 +656,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$java_net_URL$openStream(Class<?> callerClass, java.net.URL that) {
|
|
|
if (isNetworkUrl(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrl(that)) {
|
|
|
+ checkURLFileRead(callerClass, that);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -657,6 +665,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$java_net_URL$getContent(Class<?> callerClass, java.net.URL that) {
|
|
|
if (isNetworkUrl(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrl(that)) {
|
|
|
+ checkURLFileRead(callerClass, that);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -664,6 +674,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$java_net_URL$getContent(Class<?> callerClass, java.net.URL that, Class<?>[] classes) {
|
|
|
if (isNetworkUrl(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrl(that)) {
|
|
|
+ checkURLFileRead(callerClass, that);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -673,22 +685,37 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
"sun.net.www.protocol.mailto.MailToURLConnection"
|
|
|
);
|
|
|
|
|
|
+ private static final List<String> FILE_URL_CONNECT_CLASS_NAMES = List.of("sun.net.www.protocol.file.FileURLConnection");
|
|
|
+
|
|
|
private static final Set<String> NETWORK_PROTOCOLS = Set.of("http", "https", "ftp", "mailto");
|
|
|
|
|
|
+ private static final Set<String> FILE_PROTOCOLS = Set.of("file");
|
|
|
+
|
|
|
private static boolean isNetworkUrl(java.net.URL url) {
|
|
|
return NETWORK_PROTOCOLS.contains(url.getProtocol());
|
|
|
}
|
|
|
|
|
|
+ private static boolean isFileUrl(java.net.URL url) {
|
|
|
+ return FILE_PROTOCOLS.contains(url.getProtocol());
|
|
|
+ }
|
|
|
+
|
|
|
private static boolean isNetworkUrlConnection(java.net.URLConnection urlConnection) {
|
|
|
var connectionClass = urlConnection.getClass();
|
|
|
return HttpURLConnection.class.isAssignableFrom(connectionClass)
|
|
|
|| ADDITIONAL_NETWORK_URL_CONNECT_CLASS_NAMES.contains(connectionClass.getName());
|
|
|
}
|
|
|
|
|
|
+ private static boolean isFileUrlConnection(java.net.URLConnection urlConnection) {
|
|
|
+ var connectionClass = urlConnection.getClass();
|
|
|
+ return FILE_URL_CONNECT_CLASS_NAMES.contains(connectionClass.getName());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void check$java_net_URLConnection$getContentLength(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -696,6 +723,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$java_net_URLConnection$getContentLengthLong(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -703,6 +732,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$java_net_URLConnection$getContentType(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -710,6 +741,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$java_net_URLConnection$getContentEncoding(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -717,6 +750,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$java_net_URLConnection$getExpiration(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -724,6 +759,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$java_net_URLConnection$getDate(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -731,6 +768,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$java_net_URLConnection$getLastModified(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -743,6 +782,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -755,6 +796,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -767,6 +810,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -774,6 +819,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$java_net_URLConnection$getContent(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -781,6 +828,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$java_net_URLConnection$getContent(Class<?> callerClass, java.net.URLConnection that, Class<?>[] classes) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -809,6 +858,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$sun_net_www_URLConnection$getHeaderField(Class<?> callerClass, java.net.URLConnection that, String name) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -816,6 +867,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$sun_net_www_URLConnection$getHeaderFields(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -823,6 +876,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$sun_net_www_URLConnection$getHeaderFieldKey(Class<?> callerClass, java.net.URLConnection that, int n) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -830,6 +885,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$sun_net_www_URLConnection$getHeaderField(Class<?> callerClass, java.net.URLConnection that, int n) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -837,6 +894,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$sun_net_www_URLConnection$getContentType(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -844,6 +903,8 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
public void check$sun_net_www_URLConnection$getContentLength(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
if (isNetworkUrlConnection(that)) {
|
|
|
policyManager.checkOutboundNetworkAccess(callerClass);
|
|
|
+ } else if (isFileUrlConnection(that)) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2621,4 +2682,66 @@ public class ElasticsearchEntitlementChecker implements EntitlementChecker {
|
|
|
) {
|
|
|
policyManager.checkFileRead(callerClass, that);
|
|
|
}
|
|
|
+
|
|
|
+ private void checkURLFileRead(Class<?> callerClass, URL url) {
|
|
|
+ try {
|
|
|
+ policyManager.checkFileRead(callerClass, Paths.get(url.toURI()));
|
|
|
+ } catch (URISyntaxException e) {
|
|
|
+ // We expect this method to be called only on File URLs; otherwise the underlying method would fail anyway
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void check$sun_net_www_protocol_file_FileURLConnection$connect(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void check$sun_net_www_protocol_file_FileURLConnection$getHeaderFields(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void check$sun_net_www_protocol_file_FileURLConnection$getHeaderField(
|
|
|
+ Class<?> callerClass,
|
|
|
+ java.net.URLConnection that,
|
|
|
+ String name
|
|
|
+ ) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void check$sun_net_www_protocol_file_FileURLConnection$getHeaderField(Class<?> callerClass, java.net.URLConnection that, int n) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void check$sun_net_www_protocol_file_FileURLConnection$getContentLength(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void check$sun_net_www_protocol_file_FileURLConnection$getContentLengthLong(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void check$sun_net_www_protocol_file_FileURLConnection$getHeaderFieldKey(
|
|
|
+ Class<?> callerClass,
|
|
|
+ java.net.URLConnection that,
|
|
|
+ int n
|
|
|
+ ) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void check$sun_net_www_protocol_file_FileURLConnection$getLastModified(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void check$sun_net_www_protocol_file_FileURLConnection$getInputStream(Class<?> callerClass, java.net.URLConnection that) {
|
|
|
+ checkURLFileRead(callerClass, that.getURL());
|
|
|
+ }
|
|
|
}
|