I have a fully working web app made with MVC5 and Aspnet Identity (local accounts + cookie based auth). We ran a security audit in the site and the results showed that our site is vulnerable to session hijacking. The steps to reproduce the vulnerability are the following:
1 Log in with a valid user 2 Copy the cookie value from request 3 Log out 4 Request any protected page adding the copied cookie to the request headers
Even though the browser deletes the cookie in the browser and the user is logged out succesfully, THE COOKIE VALUE IS STILL VALID. In other words, what our client's security department is asking for is to MAKE THE COOKIE INVALID SERVER SIDE.
So far I tried to change the security stamp of the cookie in the logout controller but the cookie is still valid.
Here´s my auth configuration, set to expire the token 24 hours after the initial login
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromDays(1),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
Here´s my logoff controller
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
string userId = User.Identity.GetUserId();
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
UserManager.UpdateSecurityStampAsync(userId);
return RedirectToAction("Index", "Home");
}
Right now, the result is the same: anyone can use the cookie to impersonate the original loggedin user after that user logoff.
What I expect to accomplish is to log out and make that specific cookie value to be invalid server side so no one can use it after that logout. In case the user doesn't explicitly logoff, that cookie should be invalid 1 day later.