Publicizing of private data when using inner classes

Revision as of 16:44, 13 April 2006 by Jeff Williams (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Java byte code has no notion of an inner class; therefore inner classes provide only a package-level security mechanism. Furthermore, the inner class gets access to the fields of its outer class even if that class is declared private.


  • Confidentiality: "Inner Classes" data confidentiality aspects can often be overcome.

Exposure period

Implementation: This is a simple logical flaw created at implementation time.


  • Languages: Java
  • Operating platforms: Any

Required resources




Likelihood of exploit


Avoidance and mitigation

  • Implementation: Using sealed classes protects object-oriented encapsulation paradigms and therefore protects code from being extended in unforeseen ways.
  • Implementation: Inner Classes do not provide security. Warning: Never reduce the security of the object from an outer class, going to an inner class. If your outer class is final or private, ensure that your inner class is private as well.


A common misconception by Java programmers is that inner classes can only be accessed by outer classes. Inner classes' main function is to reduce the size and complexity of code. This can be trivially broken by injecting byte code into the package. Furthermore, since an inner class has access to all fields in the outer class - even if the outer class is private - potentially access to the outer classes fields could be accidently compromised.


In Java:

private class Secure(){

  private password="mypassword"
  public class Insecure(){...}


Related problems

Not available.