FormsAuthentication.SignOut()不会使FormsAuthenticationTicket到期

问题描述 投票:1回答:1

首先,这不是ASP.NET会话未到期的问题,我们在注销时清除,放弃和删除每个cookie。

这是关于FormsAuthentication.SignOut()在调用时不会使票证到期,并允许复制cookie内容的人在其他地方手动创建cookie,并且仍然能够访问在注销后现在要阻止的所有内容。

以下是我们注销方法的要点:

HttpContext.Current.User = null;
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

HttpContext.Current.Session.Clear();
HttpContext.Current.Session.Abandon();
HttpContext.Current.Session.RemoveAll();
HttpContext.Current.Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));

FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();

我们还让ASP通过我们的Web.config以及管理FormsAuthentication的其他任何东西来管理故障单的创建和身份验证。这是配置中的内容:

<authentication mode="Forms">
    <forms name="COOKIENAME" loginUrl="~/PAGE_THAT_REDIRECTS_TO_LOGIN.aspx" defaultUrl="~/PAGE_THAT_REDIRECTS_TO_LOGIN_OR_PROPER_PAGE_IF_LOGGED_IN.aspx" cookieless="UseCookies" timeout="60" />
</authentication>

现在,为什么这是一个问题?简单来说,这是一个安全问题,好像有人获取cookie并使其保持活动状态,即使用户已断开连接,他们也可以访问与cookie匹配的用户。

是否有一种强制FormsAuthenticationTicket过期的正确方法?我尝试解密它,但一切都是readonly,我也尝试创建一个新的过期票并加密它,但它不会覆盖旧票。

谢谢

版本:.NET 4.5.1,ASP.NET(不是Core)

asp.net session cookies forms-authentication formsauthenticationticket
1个回答
0
投票

基本问题是使用Microsoft .net Core cookie Management,它无法正确处理cookie的生命周期。

我曾多次面对这个问题,现在主要使用.Net核心。

要解决此问题,我们需要覆盖其cookie管理类,并实现ITicketStore接口。

https://github.com/aspnet/Security/blob/master/src/Microsoft.AspNetCore.Authentication.Cookies/CookieAuthenticationOptions.cs#L136

下面的文章可以帮助您详细实现。

https://mikerussellnz.github.io/.NET-Core-Auth-Ticket-Redis/

我希望它有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.