Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider Java v3.0

...

Wiki Markup
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.

...

Code Block
bgColor#FFcccc
public class ExceptionExample {
   public static void untrustedCode() {
     Date now = new Date();
     Class<?>Class&lt;?&gt; dateClass = now.getClass();
     createInstance(dateClass);
    }

    public static void createInstance(Class<?>Class&lt;?&gt; dateClass) {
      try { // Create another Date object using the Date Class
        Object o = dateClass.newInstance();
        
        if (o instanceof Date) {
          Date d = (Date)o;
          System.out.println("&quot;The time is: "&quot; + d.toString());
        }
      }
      catch (InstantiationException ie) { System.out.println(ie.toString()); }
      catch (IllegalAccessException iae) { System.out.println(iae.toString()); }    	
    }
}

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

References

Wiki Markup
\[[Gong 03|AA. Java References#Gong 03]\] Section 4.3.2, Class Loader Delegation Hierarchy
\[[SCG 07|AA. Java References#SCG 07]\] Guideline 6-2 Safely invoke standard APIs that bypass SecurityManager checks depending on the immediate caller's class loader

...

SEC01-J. Provide sensitive mutable classes with unmodifiable wrappers      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;02. Platform Security (SEC)      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SEC03-J. Do not use APIs that perform access checks against the immediate caller