【问题标题】:Is cookie provided by CookieAuthentication middleware secure?CookieAuthentication 中间件提供的 cookie 是否安全?
【发布时间】:2016-09-21 19:54:33
【问题描述】:

我使用app.UseCookieAuthentication如下(只是一个简单的例子);

app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
    AuthenticationScheme = "MyAuthScheme",
    AutomaticAuthenticate = true,
});

然后我在某处手动创建ClaimsPrincipal 并登录用户:

var claimCollection = new List<Claim>() 
{
    new Claim(ClaimTypes.Name, "First user"),
    new Claim(ClaimTypes.Role, "User"),
    new Claim(ClaimTypes.Email, "first@user.com")
};
var claimsIdentity = new ClaimsIdentity(claimCollection);
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);

await context.Authentication.SignInAsync("MyAuthScheme", claimsPrincipal);

因此生成的 cookie 将包含有关用户角色的信息。

现在的问题是:这样生成的 cookie 安全吗?我的意思是 ASP.NET 是否以某种方式对其进行加密,因此最终用户无法以某种方式手动修改它,例如服务器会认为用户是管理员? 当用户修改cookie时,服务器会注意到cookie已损坏吗?

【问题讨论】:

    标签: asp.net cookies asp.net-core asp.net-authentication


    【解决方案1】:

    是的。

    是的,它是加密的,所以你看不到内容。

    是的,它已签名,因此会检测到篡改。

    【讨论】:

      猜你喜欢
      • 2011-05-17
      • 2011-03-08
      • 2013-09-29
      • 2014-07-04
      • 1970-01-01
      • 1970-01-01
      • 2011-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多