...
Care must be taken when using these APIs. In particular, trusted code should not accept Class
objects from untrusted code for further use. For example, if trusted code is loaded by the bootstrap class loader, it can create an instance of a sensitive system class by using the the newInstance()
method on the Class
object. If the method that creates the instance is visible to untrusted code, no security manager checks are carried out to prohibit the untrusted code from indirectly creating the class instance (untrusted code must pass the class loader comparison check).
Similarly, instances of trusted Class
objects should not be returned to untrusted code. Security vulnerabilities can arise if the untrusted code's An untrusted caller can invoke the affected APIs and bypass security checks if its class loader is the same as or the delegation ancestor of the trusted code's class loader.
...
With respect to the ClassLoader
object APIs, security manager checks may also get bypassed depending on the immediate caller's class loader. Consider for instance, the ClassLoader.getSystemClassLoader()
and ClassLoader.getParent()
methods that operate on a ClassLoader
object. In the presence of a security manager, these methods succeed only if the immediate caller's class loader is the delegation ancestor of the current ClassLoader
object's class loader or if the immediate caller's class loader is the same as the the current ClassLoader
object's class loader or if the code in the current execution context has the RunTimePermission
, namely "getClassLoader
".
Untrusted As noted earlier, untrusted code can bypass the security checks if its classloader is either the same or a delegation ancestor of the current class loader. Consequently, care must be taken while specifying the parent of a trusted classloader. Likewise, trusted code should not use a classloader instance supplied by untrusted code. For instance, a class loader instance obtained from untrusted code should not be used to load a trusted class that performs some sensitive operation. Also, a trusted classloader that performs security sensitive operations should never be made available to untrusted code by returning its instance.
...