2015-09-30 18 views
5

私のアプリケーションで認証(Owinミドルウェア)にasp.net identity 2.0を使用しています。 セッションハイジャック: 私はIdentityがAspNet.ApplicationCookie.thenを作成し、AspNet.ApplicationCookieの値をコピーしました。アプリケーションからログアウトしました。ログアウト後、手動でクッキーを作成しています(AspNet.ApplicationCookie)。私のホームページ。特権MVC5でのエスカレーションとセッションのハイジャック

権限昇格:私は、ユーザーコピーAI(AspNet.ApplicationCookie)彼のクッキーとしてログイン同時に と私はBIがユーザーBのクッキーを編集していますユーザとしてログインout.Afterログインして貼り付けたユーザーA Cookieを保存して保存しました。ブラウザを更新した後、私はUserAのアクセスと認証を取得できます。

私はすべてのセッションをクリアしていて、すべてのクッキーを削除します。ログアウトすると、Asp.Netのアイデンティティ(Owin)は毎回新しいAspNet.ApplicationCookieを生成します。しかし、それでも古いクッキーを受け入れ、 。どうしてか分かりません? ログアウト後、古い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); 
    } 

答えて

2

私のログインコントローラのコードです。複数のブラウザからサインインしたり、他のすべてのブラウザではなく「ログアウト」をクリックしたブラウザでのみログアウトすることができます。

ログアウトすると、ユーザはSecurityStampを更新してから、セキュリティ・スタンプの有効期限を非常に短く設定することができます。

これはセキュリティスタンプを変更します:

await userManager.UpdateSecurityStampAsync(user.Id); 

あなたのログアウト方法でこれを置きます。

そして、あなたのStartup.Auth.csこのようにUseCookieAuthenticationを変更中:

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.FromMinutes(1), // set this low enough to optimise between speed and DB performance 
      regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)), 
    } 
});    

このアプローチの唯一の欠点を - ログアウト手順が実行されていないとき - 何も起こりません。ログアウトが発生すると、他のすべてのセッションがログアウトされます。

関連する問題