Cookies without Secure

Cookies without Secure in C#

Description

A cookie without Secure can be sent over HTTP and exposed to an attacker observing the network.

Potential impact

Someone who obtains a valid session or authentication cookie may gain access to the user’s account.

Remediation

Set CookieOptions.Secure = true on sensitive cookies. When configuring the policy for a component that issues them, use CookieSecurePolicy.Always.

Examples

Before

csharp
response.Cookies.Append("sid", value);

After

csharp
response.Cookies.Append("sid", value, new CookieOptions { Secure = true });

Check the response’s Set-Cookie header for the Secure attribute on sid.

References