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以更新时间戳. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- MVC 3指定远程验证的验证触发器
- ASP.NET开发服务器或本地主机IIS?
- asp.net-core – 为什么要在本地运行IIS Express?
- asp.net – url重写模式中^ ON $和^ OFF $的含义是什么,以及
- asp.net-mvc – 如何本地化枚举并使用类似于Html.SelectLis
- asp.net-mvc – IoC Castle Windsor – 没有为此对象定义的
- asp.net-mvc – 应用偏移量时表示的UTC时间必须介于0到10,0
- asp.net – 如何手动停止kestrel服务器
- asp.net-mvc – Url.Action映射Route属性的错误链接
- asp.net-mvc-3 – 如何使用MVC中的存储库模式创建动态的多个
- asp.net-mvc-4 – 如何在MVC4 ViewModel,Control
- asp.net-mvc – 使用强类型对象保持控制器和视图
- asp.net-mvc – 与asp.net MVC中的ExceptionHand
- asp.net-mvc – 元素’标题’出现次数太少,ASP.N
- asp.net-mvc – MVC Preview 5 – 将视图呈现为字
- asp.net – 为什么Page.PreviousPage始终为null?
- asp.net – 有效的密码加密
- asp.net-mvc – Structuremap处理DataContext对象
- asp.net – 无法加载类型’MyProject.MvcApplica
- asp.net – 使用IIS和ASP .Net实现负载均衡