asp.net-mvc – 使旧会话Cookie无效 – ASP.Net标识
|
一家外部公司已经对我正在开发的ASP.NET MVC 5应用程序进行了一些渗透测试. 他们提出的问题如下所述
我们正在使用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中克隆先前经过身份验证的请求,并让应用程序接受它. 编辑:我更新的Logoff方法 [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(DefaultAuthenticationTypes.ApplicationCookie);正如Jamie正确建议的那样.能够再次使用相同的cookie登录是设计的. Identity不会创建内部会话来跟踪所有已登录的用户,如果OWIN获得了击中所有框的cookie(即上一个会话中的副本),它将允许您登录. 如果您在更新安全标记后仍然可以登录,则很可能OWIN无法获取ApplicationUserManager.确保在app.UseCookieAuthentication上方有这一行 app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); 或者,如果您正在使用DI,请从DI获取ApplicationUserManager: app.CreatePerOwinContext(() => DependencyResolver.Current.GetService<ApplicationUserManager>()); 还要将validateInterval:TimeSpan.FromMinutes(30)减少到更低的值 – 我通常会在几分钟内解决.这是Identity将auth-cookie中的值与数据库中的值进行比较的频率.完成比较后,Identity会重新生成cookie以更新时间戳. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ASP.NET Web API 2:通过本机移动(iOS)应用程序与外部提供程
- asp.net-mvc-3 – MVC绑定到带有列表属性的模型忽略其他属性
- 如何设置特定于ASP.NET请求的log4net上下文属性?
- 如何在ASP.NET中的GridView中定义CellPadding
- asp.net – 如何在vNext项目中的方法上应用OutputCache属性
- asp.net-mvc – 在ASP.NET MVC控制器结果中设置HTTP状态不呈
- 日志记录 – 如何在ASP.NET MVC 6中注册ILogger进行注入
- asp.net-mvc – 使用ASP.NET会员资格和配置文件与MVC,如何创
- ASP.NET Ajax库死了吗?
- asp.net-core – 如何使用FluentValidation.AspNetCore和Fl
- asp.net – DotLess的“web”属性究竟做了什么?
- asp.net – 我可以在一个Web项目中拥有多个web.c
- asp.net-mvc-2 – 关于nginx / mono 2.8的ASP.Ne
- asp.net-mvc – 使URL特定于(通过路由)
- .net – MultipartFormDataStreamProvider vs Ht
- 在ASP.Net网站项目中混合VB.Net和C#代码?
- asp.net – 直接将.aspx转换为.pdf [已关闭]
- 如何编译x64 asp.net网站?
- asp.net – ASPxComboBox,如何设置所选项?
- asp.net – Web发布的密码不同于我的Azure管理员
