Mat*_*ost 5 oauth-2.0 jwt asp.net-web-api single-page-application asp.net-core-mvc
安全问题:根据https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/,许多JWT库使用令牌本身来确定签名算法.
这是我们的用例:我们想要创建一个登录机制,使用硬凭证(用户名/密码)验证用户,然后返回一个JWT令牌,例如3天的生命周期.令牌应包含用户名,签名应保证令牌不能"伪造".
我们可以在Web API/MVC 6中使用哪些库?重要的是可以在解码时指定签名算法以避免漏洞.
如果可能,我们希望避免集成复杂的OAuth组件.
我正在使用该System.IdentityModel.Tokens.Jwt
库,我刚刚检查了这个问题。我生成了一个令牌并在其中一个测试中验证了它,然后我删除了将signingCredentials
alg 更改为 none 的令牌。"alg":"none"
验证失败时生成的 JWT 。
这是我生成令牌的方式:
public string GenerateToken(SSOContext context, SignatureSettings settings)
{
var token = new JwtSecurityToken(
issuer: "MyIssuer",
audience: "MyAudience",
claims: GetClaims(context),
//comment the below line to generate a 'none' alg
signingCredentials: new X509SigningCredentials(settings.Certificate),
notBefore: DateTime.UtcNow,
expires: DateTime.UtcNow.AddHours(1)
);
return new JwtSecurityTokenHandler().WriteToken(token);
}
Run Code Online (Sandbox Code Playgroud)
当我验证令牌时,我收到了预期的异常消息
IDX10504:无法验证签名,令牌没有签名:
归档时间: |
|
查看次数: |
2066 次 |
最近记录: |