【发布时间】:2016-03-05 09:28:51
【问题描述】:
一家外部公司对我正在开发的 ASP.NET MVC 5 应用程序进行了一些渗透测试。
他们提出的一个问题如下所述
与会话管理链接的 cookie 称为 AspNet.ApplicationCookie。当手动输入时,应用程序对用户进行身份验证。即使用户从应用程序中注销,cookie 仍然有效。这意味着,旧会话 cookie 可用于在无限时间范围内进行有效身份验证。在插入旧值的那一刻,应用程序接受它并用新生成的 cookie 替换它。因此,如果攻击者获得对现有 cookie 之一的访问权限,则会创建有效会话,并具有与过去相同的访问权限。
我们正在使用 ASP.NEt Identity 2.2
这是我们在帐户控制器上的注销操作
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
AuthenticationManager.SignOut();
return RedirectToAction("Login", "Account");
}
在startup.auth.cs中
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
ExpireTimeSpan = TimeSpan.FromHours(24.0),
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, int>(
validateInterval: TimeSpan.FromMinutes(1.0),
regenerateIdentityCallback: (manager, user) =>
user.GenerateUserIdentityAsync(manager),
getUserIdCallback: (id) => (Int32.Parse(id.GetUserId())))
}
});
我原以为框架会处理使旧会话 cookie 无效的问题,但浏览 Owin.Security 源代码时似乎没有。
如何在注销时使会话 cookie 失效?
编辑Jamie Dunstan 的建议我已经添加了AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);,但没有任何区别。我仍然可以退出应用程序,在 Fiddler 中克隆之前经过身份验证的请求,并让它被应用程序接受。
编辑:我更新的注销方法
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> LogOff()
{
var user = await UserManager.FindByNameAsync(User.Identity.Name);
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
await UserManager.UpdateSecurityStampAsync(user.Id);
return RedirectToAction("Login", "Account");
}
【问题讨论】:
-
您是否尝试将
AuthenticationManager.Signout();替换为AuthenticationManager.Signout(DefaultAuthenticationTypes.ApplicationCookie);?无参数注销似乎有点不一致。 -
干杯。完成,但我仍然可以退出应用程序,然后在 fiddler 中克隆先前经过身份验证的请求并接受它
-
我还从 startup.Auth 中删除了 Expiretimespan。没有区别。
-
我能想到的最好办法是在调用
SignOut之后手动调用UserManager.UpdateSecurityStampAsync(userId);。你可以试试这个,看看它是否有效? -
那行不通。用户注销后,仍然可以通过 fiddler 使用先前经过身份验证的请求。
标签: asp.net-mvc asp.net-identity owin asp.net-identity-2