is this Singleton resistant to both Serialization and Reflection Attacks?

后端 未结 5 442
死守一世寂寞
死守一世寂寞 2021-02-04 22:25

Is the following code resistant to both Serialization and Reflection Attacks?

public class Example{
  private static Example instance=new Example();

  private E         


        
5条回答
  •  面向向阳花
    2021-02-04 22:53

    OO design is not meant to prevent attacks, IMHO. It can be useful to prevent inappropriate usage of your classes and bugs due to bad comprehension, irrespect of the contract, incompetence, or programming errors, though.

    Since your Example class is not serializable, I would say that serialization is not a problem in this case. Regarding reflection, if someone uses it to create another instance of your singleton, then he's obviously malicious IMO, and risks shooting himself in the foot anyway.

提交回复
热议问题