我有一个使用MVC5和Aspnet Identity(本地帐户+基于cookie的身份验证)制作的可以正常运行的Web应用程序。我们在网站上进行了安全审核,结果表明我们的网站容易受到会话劫持的攻击。重现此漏洞的步骤如下:
1使用有效用户登录 2复制请求中的cookie值 3注销 4请求任何受保护的页面,将复制的cookie添加到请求标头中
即使浏览器删除了浏览器中的cookie并成功注销了用户,COOKIE值仍然有效。换句话说,我们客户的安全部门要求的是让COOKIE INVALID SERVER SIDE。
到目前为止,我尝试在注销控制器中更改cookie的安全性标记,但是cookie仍然有效。
这是我的身份验证配置,设置为在首次登录后24小时使令牌失效
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))
}
});
这是我的注销控制器
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
string userId = User.Identity.GetUserId();
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
UserManager.UpdateSecurityStampAsync(userId);
return RedirectToAction("Index", "Home");
}
现在,结果是相同的:任何人都可以使用cookie来模拟原始注销用户。
我希望完成的工作是注销并使其特定的cookie值成为无效的服务器端,以便在注销后没有人可以使用它。如果用户没有明确注销,则该Cookie应该在1天后失效。