C# solution to keeping cookies safe
Recently our security engineer strongly suggested that we ensure that the sites we develop are using cookies in a safe manor. The CMS we develop with sometimes adds fun steps in the way of the "easy implementation."
The following sets all cookies within the C# project to secure, SameSite and HTTPONLY. Even if the cookie is outside of the code in the immediate project.
The following sets all cookies within the C# project to secure, SameSite and HTTPONLY. Even if the cookie is outside of the code in the immediate project.
protected void Application_EndRequest(object sender, EventArgs e) { foreach (string sCookie in Response.Cookies) { Response.Cookies[sCookie].Secure = true; Response.Cookies[sCookie].SameSite = SameSiteMode.Strict; Response.Cookies[sCookie].HttpOnly = true; } }
Comments
Post a Comment