【发布时间】:2015-09-30 22:40:59
【问题描述】:
我在我的应用程序中使用 asp.net identity 2.0 进行身份验证(Owin 中间件)。 会话劫持: 当我登录身份创建 AspNet.ApplicationCookie.then 时,我复制了 AspNet.ApplicationCookie 值。然后我从应用程序中注销。注销后,我正在手动创建 cookie(AspNet.ApplicationCookie)并进行刷新它重定向我的主页。
权限提升: 同时,我以用户 A 的身份登录。我复制了(AspNet.ApplicationCookie)他的 cookie,然后我退出了。在我以用户 B 的身份登录后,我正在编辑用户 B Cookie 并粘贴用户 A cookie 并保存它。刷新后浏览器我可以获得 UserA 的访问权限和身份验证。
当我注销时,我正在清除所有会话并删除所有 cookie。即使 Asp.Net 身份(Owin)每次都会生成新的 AspNet.ApplicationCookie。但它仍然接受旧 cookie 并给我访问权限。我不知道为什么? 谁能告诉我注销后如何使旧的 AspNet.ApplicationCookie 失效。 这是我在 Startup.Auth.cs 中的代码
public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
}
//这是注销代码
public ActionResult LogOff ( )
{
//Delete all cookies while user log out
string[] myCookies = Request.Cookies.AllKeys;
foreach ( var cookies in myCookies )
{
Response.Cookies[ cookies ].Expires = DateTime.Now.AddDays(-1);
}
Request.GetOwinContext( ).Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie);
// AuthenticationManager.SignOut( );
Session.Clear( );
Session.RemoveAll( );
Session.Abandon( );
return RedirectToAction("LoginPage", "Account");
}
//这是我的登录控制器代码
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindAsync(model.UserName, model.Password);
if (user != null)
{
await SignInAsync(user, model.RememberMe);
return RedirectToLocal(returnUrl);
}
else
{
ModelState.AddModelError("", "Invalid username or password.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
【问题讨论】:
标签: c# asp.net cookies owin asp.net-identity-2