简体   繁体   English

有没有办法清除服务器端OWIN /身份验证数据?

[英]Is there a way to clear server side OWIN / authentication data?

After a recent security scan, the info sec team said they do not like the fact they can save the .AspNet.ApplicationCookie value, and use it again afterwards allowing the user access to the site. 在最近的安全扫描之后,info sec团队表示他们不喜欢他们可以保存.AspNet.ApplicationCookie值,然后再次使用它,允许用户访问该站点。

After reading around, I understand this is standard behaviour but I have to find a way of completely killing a session upon signing the user out. 阅读后,我明白这是标准行为,但我必须找到一种方法,在签署用户时完全杀死会话。

My understanding is a little thin here so my searching is bringing up very little. 我的理解有点薄,所以我的搜索很少。 Is there a way of going about this? 有办法解决这个问题吗?

A late reply, but for those that come across this: 迟到的回复,但对于那些遇到这个问题:

We handled this by adding a custom attribute that validates a thumbprint. 我们通过添加验证指纹的自定义属性来处理此问题。 We use the attribute for any page behind a login. 我们对登录后面的任何页面使用该属性。

The following is a rough example of how this is achieved. 以下是如何实现这一目标的粗略示例。

The thumbprint is created at sign in and added to cache: 指纹在登录时创建并添加到缓存中:

    private void OwinSignIn(tblUser user)
    {
        var thumbPrint = Guid.NewGuid();
        var claims = new List<Claim>
        {
            ....
            new Claim(ClaimTypes.Thumbprint, thumbPrint.ToString())
        };


        MemoryCache.Default.Set(thumbPrint.ToString(), true, new CacheItemPolicy() { AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(60) });
}

The attribute then looks for this thumbprint and acts accordingly: 然后该属性查找此指纹并相应地执行操作:

public class ValidateThumbprint : FilterAttribute, IAuthorizationFilter
{
    public void OnAuthorization(AuthorizationContext filterContext)

    var identity = (ClaimsIdentity)filterContext.HttpContext.User.Identity;
    var thumbPrint = identity.Claims?.Where(s => s.Type == ClaimTypes.Thumbprint).First().Value;

    if (thumbPrint != null)
    {
        if (MemoryCache.Default.Contains(thumbPrint))
        {
            return;
        }
    }
        // handle invalid thumbprint
}

I am not sure if this is the best way and most secure way, but it does prevent saving and reusing the cookie after logging out. 我不确定这是否是最好的方式和最安全的方式,但它确实阻止了在注销后保存和重用cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM