Are there any reasons why static classes in Asp.Net can lead to a security threat? Do not objects just live in current session ?
Thank you!
Are there any reasons why static classes in Asp.Net can lead to a security threat? Do not objects just live in current session ?
Thank you!
Objects live in a so called AppPool
in the IIS. As long as that is not recycled, objects with static lifetime will be available. As one cannot reliably know when recycling happens, having static variables is a bad idea either way. Using them to hold data between calls or assuming they will not hold data between calls is both equally dangerous.
That said, if your static class does not hold data and only consists of methods, that's perfectly fine.
Static class has no instance, and consequently you should not be keeping any state of any object in side them. So theoretically it shouldn't be an issue with the security of designed correctly.
Now static variables on the other side could cause security issue if used improperly.
For example if variable like isLoggedIn is static, once one person logs in, every other user is automatically logged in because the variable will be true for every instance of the class using it.