Interface RulesApplier
-
Method Summary
Modifier and TypeMethodDescriptionvoidapplyRulesTo(RulesBuilder builder) Applies a set of rules to the given builder.static RulesApplierReturns an applier which allows reflection operations, but they are checked to ensure that the corresponding constructor or method is allowed by the other rules.static RulesApplierReturns an applier of rules for the java.base module, which denies operations that are considered harmful.
-
Method Details
-
applyRulesTo
Applies a set of rules to the given builder. -
java_base
Returns an applier of rules for the java.base module, which denies operations that are considered harmful. This consists of:- Reading and writing arbitrary files, directly or indirectly
- Creating network sockets
- Opening URLs
- Starting processes
- Loading native code or calling restricted
FFMoperations (*) - Using reflection to bypass any rules
- Reading resources from other
ClassLoadersorModules - Reading sensitive system properties or changing the system properties
- Altering shared settings (current locale, time zone, etc.)
- Creating
ObjectInputStreams - Defining new
Modules - Exiting the current process
- Changing sensitive thread settings (priority, etc. **)
- Using the
spipackages in thejava.basemodule - Altering
Providerproperties - Closing or shutting down
ForkJoinPools - Loading classes into
ProtectionDomains
* Loading native code or calling restricted FFM operations is allowed when:
- the
--enable-native-accessoption is used - the caller is a named module
- and the Java version is at least 22. (see also JEP 454)
** A few thread settings can be changed if the thread hasn't started yet: name, daemon status, the context
ClassLoader, and the thread's own uncaught exception handler. -
checkReflection
Returns an applier which allows reflection operations, but they are checked to ensure that the corresponding constructor or method is allowed by the other rules. These rules applied automatically when thejava_baserules are applied.Access is checked when
ConstructorandMethodinstances are acquired, and not when they're invoked. Custom deny rules perform a check at that time, possibly resulting in an exception being thrown. For methods which return an array, a filtering step is applied which removes elements which cannot be accessed.The following
Classmethods have custom deny actions applied:getConstructor- can throw aNoSuchMethodExceptiongetConstructors- can filter the resultsgetDeclaredConstructor- can throw aNoSuchMethodExceptiongetDeclaredConstructors- can filter the resultsgetDeclaredMethod- can throw aNoSuchMethodExceptiongetDeclaredMethods- can filter the resultsgetEnclosingConstructor- can throw aNoSuchMethodErrorgetEnclosingMethod- can throw aNoSuchMethodErrorgetMethod- can throw aNoSuchMethodExceptiongetMethods- can filter the resultsgetRecordComponents- can filter the results
Methods which return
MethodHandleinstances are checked using the same strategy as for reflection. Custom deny actions are defined for the followingLookupmethods, which can throw aNoSuchMethodException:Methods defined by
AccessibleObjectwhich enable access to class members are denied. CallingsetAccessiblecauses anInaccessibleObjectExceptionto be thrown, except when the caller module is the same as the target module. CallingtrySetAccessibledoes nothing, and instead the caller gets a result offalse.Calling
Proxy.newProxyInstancethrows aSecurityExceptionif any of the given interfaces have any denied operations. Without this check, anInvocationHandlercould get access to a deniedMethod, bypassing the other reflection checks, and thus allowing method calls on other instances.
-