Adding a @JoelEtherton solution to fix a discovered security vulnerability. This vulnerability occurs if users request HTTP and are redirected to HTTPS, but the session cookie is set to be secure on the first HTTP request. According to McAfee Secure, this is a security vulnerability.
This code will protect cookies only if the request uses HTTPS. Session cookie expires if not HTTPS.
// this code will mark the forms authentication cookie and the // session cookie as Secure. if (Request.IsSecureConnection) { if (Response.Cookies.Count > 0) { foreach (string s in Response.Cookies.AllKeys) { if (s == FormsAuthentication.FormsCookieName || s.ToLower() == "asp.net_sessionid") { Response.Cookies[s].Secure = true; } } } } else { //if not secure, then don't set session cookie Response.Cookies["asp.net_sessionid"].Value = string.Empty; Response.Cookies["asp.net_sessionid"].Expires = new DateTime(2018, 01, 01); }
Jonathan Harris May 14 '18 at 13:38 2018-05-14 13:38
source share