Versions Compared

Key

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

A non-final class or method that is not meant to be inherited can be overridden by an attacker if it is not declared final. Sometimes, it is desired that only trusted implementations should be allowed to extend the class. Declaring the class final proves to be a very stringent alternative in this case. In is overly prohibitive and in such cases, the class must be carefully designed for inheritance.

Wiki Markup
AnotherA related pitfall occurs when malicious classes are allowed to extend from a non-final class. Consider two classes belonging to different protection domains. One of them is malicious whereas the other is trusted. If the malicious class extends the trusted {{public}} non-final class and inherits without overriding a method of the trusted class, the fully qualified invocation of the malicious class's version of the method uses the protection domain of the trusted class. In this case, the trusted class's permissions are examined to execute the method. \[[Gong 03|java:AA. Java References#Gong 03]\])

...

Wiki Markup
This compliant solution installs a security manager check in the constructor of the non-final class. Access is denied if the itsecurity ismanager detecteddetects that a subclass is trying to instantiate the superclass. Only if the subclass has without the requisite permissions, is it allowed to proceed. \[[SCG 07|java:AA. Java References#SCG 07]\]

...