Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 (or immediate) 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".

As noted earlier, untrusted code can bypass the security checks if its classloader is either the same or a delegation ancestor of the immediate trusted code's 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.

...