json - JWT 是否共享/存储用于在客户端和服务器上签名的 secret ?

标签 json rest security csrf jwt

我正在脑海中解决一些与 JWT 身份验证安全性相关的架构问题,并且我正在尝试弄清楚以下内容:

  1. JWT 如何在服务器和客户端之间安全地传递 secret ?

  2. 请查看以下来自 https://stormpath.com/blog/where-to-store-your-jwts-cookies-vs-html5-web-storage/ 的摘录.....................

CSRF can be prevented by using synchronized token patterns. This sounds complicated, but all modern web frameworks have support for this.

For example, AngularJS has a solution to validate that the cookie is accessible by only your domain. Straight from AngularJS docs:

'When performing XHR requests, the $http service reads a token from a cookie (by default, XSRF-TOKEN) and sets it as an HTTP header (X-XSRF-TOKEN). Since only JavaScript that runs on your domain can read the cookie, your server can be assured that the XHR came from JavaScript running on your domain. You can make this CSRF protection stateless by including a xsrfToken JWT claim:'

{ "iss": "http://galaxies.com", "exp": 1300819380, "scopes": ["explorer", "solar-harvester", "seller"], "sub": "tom@andromeda.com", "xsrfToken": "d9b9714c-7ac0-42e0-8696-2dae95dbc33e" }

  1. 客户端如何创建并发送包含 xsrfToken 声明的有效请求,除非它可以在包含声明后首先签署 JWT? (毕竟这个 xsrfToken 是用来防止 EvilBob 伪造请求的,对吗?)

关于我目前对 JWT XSRF 过程的理解的更多细节可以在这里找到 http://spring.io/blog/2013/08/21/spring-security-3-2-0-rc1-highlights-csrf-protection/ .

最佳答案

  1. 我可以解释 Stormpath 是如何做到的,还有其他一些方法。 Stormpath 在 JWT header 中包含一个“kid”( key ID)字段,它是 API key ID/ secret 对的标识符。 JWT 使用 Secret 签名,ID 存储在 key id 字段中。当 Stormpath 验证 token 时,它可以检索 secret 。这适用于跨服务器和服务,但从不传递给客户端。使用客户端将单独的服务与 key 粘合在一起是极其不安全的。

  2. 客户端不应该生成 JWT,这需要在服务器上完成。服务器知道 XSRF token 并可以在 JWT 中对其进行签名并将其放入 cookie 中。

希望这些信息对您有所帮助!

关于json - JWT 是否共享/存储用于在客户端和服务器上签名的 secret ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34058854/

相关文章:

java - Jersey 2.x : How to add Headers on RESTful Client

rest - 如何为 Restful WS 创建 WSDL

security - netbank 登录加密狗如何工作?

apache - 如何在 Apache 上启用 TLS_FALLBACK_SCSV

javascript - 在 TypeScript 中向 JavaScript 对象添加数据

python - 遍历 Json 结构以获得多个输出,我得到一个,为什么?

json - 常规 : how do i search json with key's value and find its children in groovy

json - Postgres JSON 等效于 HSTORE 减法运算符

java - REST 请求响应和内部服务器错误

security - 提高安全性的最佳 PHP.ini 设置