编程语言
首页 > 编程语言> > 最好的方法是从Web应用程序注销某人?

最好的方法是从Web应用程序注销某人?

作者:互联网

我有一个需要用户名和密码的应用程序.当用户单击注销按钮时,它将运行:

private void LogOut()
{
    Session["SessionName"] = null;
    Session.Remove("SessionName");
    System.Web.Security.FormsAuthentication.SignOut();

    Response.Cookies.Remove("AuthCookie");
    HttpCookie c = new HttpCookie("AuthCookie");
    c.Expires = DateTime.Now.AddYears(-1);
    Response.Cookies.Add(c);

    Session.Clear();
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
    Response.Cache.SetNoStore();
    Response.Cache.SetNoServerCaching();

    Session.Abandon();

    Response.Redirect("~/user/login.aspx");
}

问题是当我测试安全性时.当我转到页面以更改数据库中的数据时,可以使用Fiddler来“记录”该请求.从应用程序注销后,我仍然可以像仍在登录一样在Fiddler中重播此请求.实际上,当我在代码中放置中断时,仍可以看到所有cookie和会话信息.只有在会话过期(从超时)之后,实际会话才会消失.

Cookie过期并放弃会话后,如何仍能看到此信息?当用户单击注销按钮时,如何完全清除cookie和会话信息?

解决方法:

根据MSDN(http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.signout.aspx),

Calling the SignOut method only removes the forms authentication cookie. The Web server does not store valid and expired authentication tickets for later comparison. This makes your site vulnerable to a replay attack if a malicious user obtains a valid forms authentication cookie.

他们提供了三种方法来减轻这种风险.只有最后一种方法(使用永久性存储来自己跟踪登录状态)将阻止实际用户重播请求.第一种方法只是缩短了漏洞的时间范围,第二种方法则使Cookie不受第三者的侵害.

标签:security,session-state,fiddler,asp-net,c
来源: https://codeday.me/bug/20191030/1971024.html