Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Securing input of private / protected methods?

normally, all sane developers are trying to secure input of all public methods (casting to proper types, validating, sanitizing etc.)

My question is: are you in your code validating also parameters passed to protected / private methods? In my opinion it is not necessary, if you securize properly parameters of public methods and return values from outside (other classes, db, user input etc...).

But I am constantly facing frameworks and apps (ie. prestashop to name one) where validation is often repeated in method call, in method body and once again for securize returned value - which, I think, is creating performace overhead and is also a sign of bad design.

like image 743
ts. Avatar asked May 17 '10 15:05

ts.


1 Answers

For protected, I think you should validate them since the method could be overridden or called from another class later and you can't assume valid inputs to the method. This is especially true if this is a component that is going to be used by other applications.

For private, I think it's a waste because you are in control of what is being passed to the methods, so that data should be validated before you ever call the private method.

like image 187
dcp Avatar answered Oct 02 '22 06:10

dcp