Versions Compared

Key

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

Wiki MarkupWhen one of the mthods methods from the highlighted table below is invoked on a {{Class}} Class, ClassLoader or Thread object, a comparison is run between the method's immediate caller's class loader and that of the object. As an example of what constitutes the immediate caller and the object, consider the method java.lang.Class.newInstance(). Here, the immediate caller is the class that contains this method call whereas the object is called the Class object, the one on which newInstance() is invoked (classObjectName.newInstance()).

Wiki Markup
 that of the {{Class}} object. According to the Java Language Specification \[[JLS 05|AA. Java References#JLS 05]\] section 4.3.2 "The Class {{Object}}": "The method {{getClass}} returns the {{Class}} object that represents the class of the object". The first ten methods shown below can be used on a {{Class}} object.

APIs capable of bypassing SecurityManager's checks

java.lang.Class.newInstance

java.lang.Class.getClassLoader

java.lang.Class.getClasses

java.lang.Class.getField(s)

java.lang.Class.getMethod(s)

java.lang.Class.getConstructor(s)

java.lang.Class.getDeclaredClasses

java.lang.Class.getDeclaredField(s)

java.lang.Class.getDeclaredMethod(s)

java.lang.Class.getDeclaredConstructor(s)

java.lang.ClassLoader.getParent

java.lang.ClassLoader.getSystemClassLoader

java.lang.Thread.getContextClassLoader

Security manager checks may get bypassed depending on the immediate caller's class loader. For instance, in Consider for instance, the ClassLoader.getSystemClassLoader() and ClassLoader.getParent() methods that operate on a ClassLoader object. In the presence of a security manager, the getSystemClassLoader and getParent 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 current one the ClassLoader object's class loader or if the code in the current execution context has the RunTimePermission, namely "getClassLoader".

Noncompliant Code Example

The createInstance method is the immediate caller of java.lang.Class.newInstance in this noncompliant example. The newInstance() method is being invoked on the dateClass Class object. The issue is that the untrustedCode method can trigger the instantiation of a new class even though it should not have the permission to do so. This behavior is not caught by the security manager.

...