Owin状态参数和CSRF

时间:2019-07-09 21:24:07

标签: asp.net security oauth-2.0 asp.net-identity owin

基于我的理解,OAuth 2.0流中的state参数旨在用作防止CSRF的防伪攻击令牌。

这是Asp.Net身份模板的默认实现

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LinkLogin(string provider)
{
    // Request a redirect to the external login provider to link a login for the current user
    return new AccountController.ChallengeResult(provider, Url.Action("LinkLoginCallback", "Manage"), User.Identity.GetUserId());
}

AccountController.ChallengeResult.ExecuteResult中,这就是我们的

public override void ExecuteResult(ControllerContext context)
{
    var properties = new AuthenticationProperties { RedirectUri = RedirectUri };
    if (UserId != null)
    {
        properties.Dictionary[XsrfKey] = UserId;
    }

    context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
}

ManageController.LinkLoginCallback()中,这就是我们的

var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(XsrfKey, User.Identity.GetUserId());

是否注意到挑战密钥为Dictionary[XsrfKey] = UserId?这意味着当状态参数被序列化时,它将包含一对"XsrfId" : {user id}的键值对,这将成为我们的防伪令牌。

虽然很难对所有用户发起大规模攻击,但是针对特定用户应该相对简单,因为CSCF令牌非常可预测。我是否缺少某些东西,或者这是安全漏洞?

0 个答案:

没有答案