rspec/rules/S3330/java/rule.adoc

30 lines
997 B
Plaintext
Raw Normal View History

2020-06-30 12:48:39 +02:00
include::../description.adoc[]
include::../ask-yourself.adoc[]
include::../recommended.adoc[]
== Sensitive Code Example
If you create a security-sensitive cookie in your JAVA code:
2020-06-30 12:48:39 +02:00
----
Cookie c = new Cookie(COOKIENAME, sensitivedata);
c.setHttpOnly(false); // Sensitive: this sensitive cookie is created with the httponly flag set to false and so it can be stolen easily in case of XSS vulnerability
----
2021-01-27 13:42:22 +01:00
By default the https://docs.oracle.com/javaee/6/api/javax/servlet/http/Cookie.html#setHttpOnly(boolean)[``++HttpOnly++``] flag is set to _false:_
2020-06-30 12:48:39 +02:00
----
Cookie c = new Cookie(COOKIENAME, sensitivedata); // Sensitive: this sensitive cookie is created with the httponly flag not defined (by default set to false) and so it can be stolen easily in case of XSS vulnerability
----
== Compliant Solution
----
Cookie c = new Cookie(COOKIENAME, sensitivedata);
c.setHttpOnly(true); // Compliant: this sensitive cookie is protected against theft (HttpOnly=true)
----
include::../see.adoc[]