我们在 ASP.Net MVC 网络应用程序中使用 Microsoft.Owin.Security.Cookies.CookieAuthenticationProvider
。
“登录”代码使用自定义类来跟踪授权信息(下例中的 userRights
)。代码如下所示:
string auth = JsonConvert.SerializeObject(userRights);
ClaimsIdentity identity = new ClaimsIdentity(new[]
{
new Claim(ClaimTypes.AuthorizationDecision, auth),
}, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(identity);
我担心的是,此信息可能存储在身份验证 cookie 中并发送到客户端,在那里可能会被操纵或更改。
源代码很好地隐藏了所发生的事情。在 VisualStudio“Go to implementation”中声明它找不到 IAuthenticationManager.SignIn
的任何实现,而 Microsoft.Owin.Security.Cookies.CookieAuthenticationProvider
的源代码只是显示了一堆Action
委托(delegate),我无法调试,因为我没有符号。
另一个问题是 Cookie replay attacks .我正在考虑通过使用这样的 session 存储来解决这两个潜在问题:
Session.Add("AuthorizationDecision", userRights);
和注销:
Session.Clear();
Session.Abandon();
AuthenticationManager.SignOut();
这样我就可以确定信息不会发送到客户端,也不会在那里被操纵。但我可能忽略了某些东西,或者我最初的担忧可能没有根据(由于代码晦涩,我无法检查)。我们的团队担心“ session 不是为了授权而创建的,可能没有加密或与使用声明一样安全”如果您的专家可以分享您的想法或通过解释声明的存储位置来消除我的担忧,那就太好了。
-- 编辑--
我继续并从身份验证声明中删除了授权(因为似乎没有人知道信息保存在哪里)。可以缓存在session中,但是session相对于cookie有一个完全独立的生命周期,所以需要进行null检查,当session不为null时还需要检查ClaimsIdentity.IsAuthenticated
.
最佳答案
对于 claim 数据的存储位置有同样的问题。关于您的问题:
My concern is that this information may be stored inside the authentication cookie and sent to the client where it could potentially be manipulated or changed.
cookies 是经过加密和签名的,因此数据在客户端既不能被查看也不能被篡改。
关于c# - 使用 CookieAuthenticationProvider 调用 AuthenticationManager.SignIn() 后 ClaimsIdentity 信息存储在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52180868/