我在我的应用程序中实现了 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.IsAuthenticated
为 True
我有几个问题:-
- 这是 Cookie 重放攻击吗?
- 我做错了什么,如果没有我会的 必须通过一些 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/