c# - OWIN OpenId 身份验证 - 注销后的事件 session

标签 c# asp.net asp.net-mvc asp.net-identity owin

我在我的应用程序中实现了 ASP.Net Cookie 身份验证和 OWIN OpenId 身份验证的混合。我正在尝试修复一个安全缺陷,即即使注销后 session 也不会失效。

中间件实现:

app.UseCookieAuthentication(
    new CookieAuthenticationOptions
    {
        AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,    
        app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
        {
            ClientId = clientId,
            Authority = authority,
        }
     }
);

Log Out Code (Based on user type):

HttpContext.GetOwinContext().Authentication.SignOut(
    OpenIdConnectAuthenticationDefaults.AuthenticationType,
    CookieAuthenticationDefaults.AuthenticationType);
    
HttpContext.GetOwinContext().Authentication.SignOut(
    CookieAuthenticationDefaults.AuthenticationType);

我正在捕获Fiddler中的流量并单击网页上的注销。当我尝试从 Fiddler 重新发出请求时,它成功完成,并且在 HttpModule 中,Application.User.Identity.IsAuthenticatedTrue

我有几个问题:-

  1. 这是 Cookie 重放攻击吗?
  2. 我做错了什么,如果没有我会的 必须通过一些 hack 来修复它,比如在缓存中存储 cookie 并 比较一下?

最佳答案

从应用程序注销时,您也必须从身份服务器注销。否则,您的应用程序将被重定向到身份服务器,重新进行身份验证并重新登录。检查通知下的以下代码片段:

app.UseCookieAuthentication(
    new CookieAuthenticationOptions
    {
        AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,    
        app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
        {
            ClientId = clientId,
            Authority = authority,
        },
        Notifications = new OpenIdConnectAuthenticationNotifications
        {
            RedirectToIdentityProvider = n =>
            {
                // if signing out, add the id_token_hint
                if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)
                {
                    var idTokenHint = n.OwinContext.Authentication.User.FindFirst("id_token");

                    if (idTokenHint != null)
                    {
                        n.ProtocolMessage.IdTokenHint = idTokenHint.Value;
                    }
                }

                return Task.FromResult(0);
            }
        }
     }
);

您将找到一些 OWIN 中间件设置示例(尽管不是您问题的直接答案)here

关于c# - OWIN OpenId 身份验证 - 注销后的事件 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58882283/

相关文章:

c# - 在 WinForms 应用程序中记录所有按钮点击

c# - 是否可以将视频流伪造为在 Skype、Lync 等中可见的虚拟摄像头?

c# - 内容管理系统安全?

c# - 具有对称加密的 SignalR

c# - WCF 和 FluentNHibernate

asp.net - 在 aspx 页面上打印 configurationmanager.appsettings 变量?

c# - 在 ASP.NET 中,对预检请求的响应未通过访问控制检查 : No 'Access-Control-Allow-Origin' header

asp.net-mvc - 您是否清理了 Visual Studio MVC 项目中未使用的脚本?

javascript - 将 JSON 转换为 ViewModel 并将 token 传递给 Controller

asp.net - 如何在 Visual Studio 2017 中重命名发布配置文件?