diff --git a/libs/entitlement/bridge/src/main/java/org/elasticsearch/entitlement/bridge/EntitlementChecker.java b/libs/entitlement/bridge/src/main/java/org/elasticsearch/entitlement/bridge/EntitlementChecker.java index 4f97d9a7d22e5..5b4727041d782 100644 --- a/libs/entitlement/bridge/src/main/java/org/elasticsearch/entitlement/bridge/EntitlementChecker.java +++ b/libs/entitlement/bridge/src/main/java/org/elasticsearch/entitlement/bridge/EntitlementChecker.java @@ -515,6 +515,10 @@ public interface EntitlementChecker { javax.net.ssl.HttpsURLConnection that ); + void check$sun_net_www_protocol_mailto_MailToURLConnection$connect(Class callerClass, java.net.URLConnection that); + + void check$sun_net_www_protocol_mailto_MailToURLConnection$getOutputStream(Class callerClass, java.net.URLConnection that); + // Network miscellanea // HttpClient#send and sendAsync are abstract, so we instrument their internal implementations diff --git a/libs/entitlement/qa/entitled-plugin/src/main/java/org/elasticsearch/entitlement/qa/entitled/EntitledActions.java b/libs/entitlement/qa/entitled-plugin/src/main/java/org/elasticsearch/entitlement/qa/entitled/EntitledActions.java index a1f59ce2f6006..2ca8adc885079 100644 --- a/libs/entitlement/qa/entitled-plugin/src/main/java/org/elasticsearch/entitlement/qa/entitled/EntitledActions.java +++ b/libs/entitlement/qa/entitled-plugin/src/main/java/org/elasticsearch/entitlement/qa/entitled/EntitledActions.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.net.URI; +import java.net.URISyntaxException; import java.net.URLConnection; import java.nio.file.Files; import java.nio.file.Path; @@ -76,4 +77,8 @@ public static URLConnection createFileURLConnection() throws IOException { var fileUrl = createTempFileForWrite().toUri().toURL(); return fileUrl.openConnection(); } + + public static URLConnection createMailToURLConnection() throws URISyntaxException, IOException { + return new URI("mailto", "email@example.com", null).toURL().openConnection(); + } } diff --git a/libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/URLConnectionNetworkActions.java b/libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/URLConnectionNetworkActions.java index a997b7d121a76..95f8b6d3de748 100644 --- a/libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/URLConnectionNetworkActions.java +++ b/libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/URLConnectionNetworkActions.java @@ -103,6 +103,17 @@ private static void withJdkFtpConnection(CheckedConsumer connectionConsumer) throws Exception { + var conn = EntitledActions.createMailToURLConnection(); + // Be sure we got the connection implementation we want + assert conn.getClass().getSimpleName().equals("MailToURLConnection"); + try { + connectionConsumer.accept(conn); + } catch (IOException e) { + // It's OK, it means we passed entitlement checks, and we tried to perform some IO + } + } + @EntitlementTest(expectedAccess = PLUGINS) static void urlOpenConnection() throws Exception { URI.create("http://127.0.0.1:12345/").toURL().openConnection(); @@ -429,4 +440,14 @@ static void sunHttpsURLConnectionImplGetContent() throws Exception { static void sunHttpsURLConnectionImplGetContentWithClasses() throws Exception { withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getContent(new Class[] { String.class })); } + + @EntitlementTest(expectedAccess = PLUGINS) + static void sunMailToURLConnectionConnect() throws Exception { + withJdkMailToConnection(URLConnection::connect); + } + + @EntitlementTest(expectedAccess = PLUGINS) + static void sunMailToURLConnectionGetOutputStream() throws Exception { + withJdkMailToConnection(URLConnection::getOutputStream); + } } diff --git a/libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/api/ElasticsearchEntitlementChecker.java b/libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/api/ElasticsearchEntitlementChecker.java index 61fc45a4f5552..3c6212f93135f 100644 --- a/libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/api/ElasticsearchEntitlementChecker.java +++ b/libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/api/ElasticsearchEntitlementChecker.java @@ -1177,6 +1177,16 @@ private static boolean isFileUrlConnection(java.net.URLConnection urlConnection) policyManager.checkOutboundNetworkAccess(callerClass); } + @Override + public void check$sun_net_www_protocol_mailto_MailToURLConnection$connect(Class callerClass, java.net.URLConnection that) { + policyManager.checkOutboundNetworkAccess(callerClass); + } + + @Override + public void check$sun_net_www_protocol_mailto_MailToURLConnection$getOutputStream(Class callerClass, java.net.URLConnection that) { + policyManager.checkOutboundNetworkAccess(callerClass); + } + @Override public void check$jdk_internal_net_http_HttpClientImpl$send( Class callerClass,