rspec/rules/S2441/java/rule.adoc
Egon Okerman d1417e82f8
Modify CWE and OWASP Top 10 links to follow standard link format (APPSEC-1134) (#3529)
* Fix all CWE references

* Fix all OWASP references

* Fix missing CWE prefixes
2024-01-15 17:15:56 +01:00

60 lines
1.8 KiB
Plaintext

== Why is this an issue?
`HttpSession` s are managed by web servers and can be serialized and stored on disk as the server manages its memory use in a process called "passivation" (and later restored during "activation").
Even though `HttpSession` does not extend `Serializable`, you must nonetheless assume that it will be serialized.
If non-serializable objects are stored in the session, serialization might fail.
=== Noncompliant code example
[source,java,diff-id=1,diff-type=noncompliant]
----
public class Address {
//...
}
HttpSession session = request.getSession();
session.setAttribute("address", new Address()); // Noncompliant; Address isn't serializable
----
=== Compliant solution
[source,java,diff-id=1,diff-type=compliant]
----
public class Address implements Serializable {
//...
}
HttpSession session = request.getSession();
session.setAttribute("address", new Address());
----
== Resources
* OWASP - https://owasp.org/Top10/A04_2021-Insecure_Design/[Top 10 2021 Category A4 - Insecure Design]
* CWE - https://cwe.mitre.org/data/definitions/579[CWE-579 - J2EE Bad Practices: Non-serializable Object Stored in Session]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Make "xxx" serializable or don't store it in the session.
'''
== Comments And Links
(visible only on this page)
=== on 27 Feb 2015, 21:11:59 Freddy Mallet wrote:
@Ann, we can link this rule to http://cwe.mitre.org/data/definitions/579.html[CWE-579]: "J2EE Bad Practices: Non-serializable Object Stored in Session"
=== on 15 Feb 2016, 19:12:14 Ann Campbell wrote:
This maps to https://www.securecoding.cert.org/confluence/x/EYDeBw[CERT MSC08-J.] but I'm not adding a reference field value or a See entry because the CERT version is currently a stub.
endif::env-github,rspecator-view[]