2020-06-30 12:48:07 +02:00
include::../description.adoc[]
include::../ask-yourself.adoc[]
include::../recommended.adoc[]
== Sensitive Code Example
2021-04-26 17:29:13 +02:00
When the ``++HttpCookie.Secure++`` property is set to ``++false++`` then the cookie will be send during an unencrypted HTTP request:
2021-02-02 15:02:10 +01:00
2020-06-30 12:48:07 +02:00
----
HttpCookie myCookie = new HttpCookie("Sensitive cookie");
myCookie.Secure = false; // Sensitive: a security-sensitive cookie is created with the secure flag set to false
----
2021-04-26 17:29:13 +02:00
The https://docs.microsoft.com/en-us/dotnet/api/system.web.httpcookie.secure?view=netframework-4.8[default value] of ``++Secure++`` flag is ``++false++``, unless overwritten by an application's configuration file:
2020-06-30 14:49:38 +02:00
2020-06-30 12:48:07 +02:00
----
HttpCookie myCookie = new HttpCookie("Sensitive cookie");
// Sensitive: a security-sensitive cookie is created with the secure flag not defined (by default set to false)
----
== Compliant Solution
2021-04-26 17:29:13 +02:00
Set the ``++HttpCookie.Secure++`` property to ``++true++``:
2020-06-30 12:48:07 +02:00
----
HttpCookie myCookie = new HttpCookie("Sensitive cookie");
2021-04-26 17:29:13 +02:00
myCookie.Secure = true; // Compliant
2020-06-30 12:48:07 +02:00
----
2021-04-26 17:29:13 +02:00
Or change the default flag values for the whole application by editing the https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms228262(v=vs.100)[Web.config configuration file]:
----
<httpCookies httpOnlyCookies="true" requireSSL="true" />
----
* the ``++requireSSL++`` attribute corresponds programmatically to the ``++Secure++`` field.
* the ``++httpOnlyCookies++`` attribute corresponds programmatically to the ``++httpOnly++`` field.
2020-06-30 12:48:07 +02:00
include::../see.adoc[]
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]