security - 为什么 JWT 需要客户端验证?

标签 security jwt digital-signature public-key-encryption

所以我的理解是,JWT 由服务器使用私钥签名,其合法性通过将公钥解密的签名与服务器和客户端的 header +有效负载进行比较来验证:

The tokens are signed by one party's private key (usually the server's), so that both parties (the other already being, by some suitable and trustworthy means, in possession of the corresponding public key) are able to verify that the token is legitimate.1

我只是想知道客户端需要验证JWT的真实性吗?我知道 SSL 使用相同的机制,在这种情况下,客户端验证对我来说很有意义,因为证书包含客户端用来加密初始握手的公钥。但我很难理解在 JWT 的情况下,公共(public)可验证性有什么好处。如果 JWT 是非法的,它无论如何都会在服务器上失败,并且客户端除了将其附加到请求之外没有做任何特殊的事情。

难道不能只在服务器上使用一些私有(private)盐进行散列来满足它的目的吗?服务器通过使用相同的盐对有效负载进行哈希处理并与签名进行比较来进行验证。在这种情况下,只有服务器可以验证,那又如何?

最佳答案

So my understanding is that a JWT is signed by the server with a private key and its legitimacy verified by comparing the public key decrypted signature against the header + payload by both/either the server and client:

这是不完整。可以使用 key 对的私钥(例如 RSA)或使用对称 key (例如 HMAC)对 JWT 进行签名。在这种情况下,相同的 key 用于签署和验证 token

I'm just wondering what need is there for the client to verify the authenticity of the JWT?

当使用非对称 key 对对 token 进行签名时,客户端会验证 token 。使用对称 key ,只有发行方知道,客户端无法验证

在这里查看我的回答:When to use RS256 for JWT?

I understand the same mechanism is used for SSL, in which case client-side verification makes sense to me as the certificate contains the public key used by the client to encrypt the initial handshake

握手中使用的一些数据由服务器使用其私钥进行数字签名(未加密),并由客户端验证

If the JWT were illegitimate, it'd fail on the server anyway, and the client isn't doing anything special aside from tacking it onto the request.

否,如果验证服务器与发卡服务器不同(再看一遍上面的链接)。

假设 token 已由第三方(例如 goggle 或 facebook)作为 oauth2 身份验证过程的结果颁发。它可以包含已连接用户的详细信息,并且已使用重定向将其提供给您的服务器,因此您不能信任调用方。您必须验证 token 是否已由预期方颁发。

关于security - 为什么 JWT 需要客户端验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50932051/

相关文章:

go - 将 AppleID 的公钥编码(marshal)为 rsa.PublicKey

python - 如何在不强制用户重新输入密码的情况下进行 Django JSON Web token 身份验证?

vb.net - 使用 itextsharp 库在 .pdf 文件中创建空签名字段

使用 ssl 形式的 WordPress 让我们加密,但主页并不完全安全。 "Attackers might be able to see images.."消息

security - 为什么 Gmail 中的链接会重定向?

api - 在 POST 中将数据安全地发送到 REST API

security - 如何防止任意客户端应用程序使用匿名 Web API?

javascript - jsonwebtoken 中的有效负载错误

c# - 如何从签名文件中获取签名者的姓名

asp.net - 将数字签名添加到 pdf 文件