CRITICAL
Rule Definition
When non-serializable object is stored as an HttpSessionState attribute, it can damage application reliablity.
ASP.NET servers by default store the HttpSessionState object, its attributes and any objects they reference in memory which limits active session state to what can be accommodated by the system memory.
Servers are configured to persistent session state to expand capacity. The server must serialize the HttpSessionState object to persist its session state.
Remediation
All the objects which are stored as session attributes in the application must declare [Serializable] attribute to serialize the session correctly.
Violation Code Sample
HttpContext.Current.Session[CURRENT_USER_KEY] = value;
this.Session.Add("lbSection", (string)((LinkButton)sender).ID.ToString());
_________________________________________________________
public class DataGlob {
String GlobName;
String GlobValue;
public void AddToSession(HttpSessionState session) {
session["glob"] = this;
}
}
Fixed Code Sample
[Serializable]
public class EqueryRaised
{
#region Private Fields
private string _queryID;
private string _reOpenID;
}
________________________________________________________
[Serializable]
public class DataGlob {
String GlobName;
String GlobValue;
public void AddToSession(HttpSessionState session) {
session["glob"] = this;
}
}
Reference
https://cwe.mitre.org/data/definitions/502.html
Related Technologies
Technical Criterion
Secure Coding - Time and State
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.