Interface RulesApplier
-
Method Summary
Modifier and TypeMethodDescriptionvoid
applyRulesTo
(RulesBuilder builder) Applies a set of rules to the given builder.static RulesApplier
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.static RulesApplier
Returns 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 FFM operations (*)
- Using reflection to bypass any rules
- Reading resources from other
ClassLoaders
orModules
- 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
spi
packages in thejava.base
module - Altering
Provider
properties - Closing or shutting down
ForkJoinPools
- Loading classes into
ProtectionDomains
* Loading native code or calling restricted FFM operations is allowed when:
- the
--enable-native-access
option 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_base
rules are applied.Access is checked when
Constructor
andMethod
instances 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 (example:Class.getMethods
), a filtering step is applied which removes elements which cannot be accessed.The following
Class
methods have custom deny actions applied:getConstructor
- can throw aNoSuchMethodException
getConstructors
- can filter the resultsgetDeclaredConstructor
- can throw aNoSuchMethodException
getDeclaredConstructors
- can filter the resultsgetDeclaredMethod
- can throw aNoSuchMethodException
getDeclaredMethods
- can filter the resultsgetEnclosingConstructor
- can throw aNoSuchMethodError
getEnclosingMethod
- can throw aNoSuchMethodError
getMethod
- can throw aNoSuchMethodException
getMethods
- can filter the resultsgetRecordComponents
- can filter the results
Methods which return
MethodHandle
instances are checked using the same strategy as for reflection. Custom deny actions are defined for the followingLookup
methods, which can throw aNoSuchMethodException
:Methods defined by
AccessibleObject
which enable access to class members are denied. CallingsetAccessible
causes anInaccessibleObjectException
to be thrown, except when the caller module is the same as the target module. CallingtrySetAccessible
does nothing, and instead the caller gets a result offalse
.Calling
Proxy.newProxyInstance
throws aSecurityException
if any of the given interfaces have any denied operations. Without this check, anInvocationHandler
could get access to a deniedMethod
, bypassing the other reflection checks, and thus allowing method calls on other instances.
-