File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed
qa/entitlement-test-plugin/src/main/java
org/elasticsearch/entitlement/qa/test
src/main/java/org/elasticsearch/entitlement/runtime/policy Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 1818 requires java .logging ;
1919 requires java .net .http ;
2020 requires jdk .net ;
21+ requires java .desktop ;
2122}
Original file line number Diff line number Diff line change 3535import java .util .zip .ZipException ;
3636import java .util .zip .ZipFile ;
3737
38+ import javax .imageio .stream .FileImageInputStream ;
39+
3840import static java .nio .charset .Charset .defaultCharset ;
3941import static java .nio .file .StandardOpenOption .CREATE ;
4042import static java .nio .file .StandardOpenOption .WRITE ;
@@ -561,5 +563,13 @@ static void httpResponseBodySubscribersOfFile_FileOpenOptions_readOnly() {
561563 HttpResponse .BodySubscribers .ofFile (readFile (), CREATE , WRITE );
562564 }
563565
566+ @ EntitlementTest (expectedAccess = ALWAYS_DENIED )
567+ static void javaDesktopFileAccess () throws Exception {
568+ // Test file access from a java.desktop class. We explicitly exclude that module from the "system modules", so we expect
569+ // any sensitive operation from java.desktop to fail.
570+ var file = EntitledActions .createTempFileForRead ();
571+ new FileImageInputStream (file .toFile ()).close ();
572+ }
573+
564574 private FileCheckActions () {}
565575}
Original file line number Diff line number Diff line change @@ -67,6 +67,8 @@ public class PolicyManager {
6767
6868 static final Class <?> DEFAULT_FILESYSTEM_CLASS = PathUtils .getDefaultFileSystem ().getClass ();
6969
70+ static final Set <String > MODULES_EXCLUDED_FROM_SYSTEM_MODULES = Set .of ("java.desktop" );
71+
7072 /**
7173 * @param componentName the plugin name; or else one of the special component names
7274 * like {@link #SERVER_COMPONENT_NAME} or {@link #APM_AGENT_COMPONENT_NAME}.
@@ -141,7 +143,13 @@ private static Set<Module> findSystemModules() {
141143 // entitlements is a "system" module, we can do anything from it
142144 Stream .of (PolicyManager .class .getModule ()),
143145 // anything in the boot layer is also part of the system
144- ModuleLayer .boot ().modules ().stream ().filter (m -> systemModulesDescriptors .contains (m .getDescriptor ()))
146+ ModuleLayer .boot ()
147+ .modules ()
148+ .stream ()
149+ .filter (
150+ m -> systemModulesDescriptors .contains (m .getDescriptor ())
151+ && MODULES_EXCLUDED_FROM_SYSTEM_MODULES .contains (m .getName ()) == false
152+ )
145153 ).collect (Collectors .toUnmodifiableSet ());
146154 }
147155
You can’t perform that action at this time.
0 commit comments