'state' 在这种情况下是什么意思? (关于将 JWT 存储在 cookie 中的讨论)
What does 'state' mean in this context? (Discussion about storing JWTs in cookies)
来自Stormpath:
Cookies, when used with the HttpOnly cookie flag, are not accessible through JavaScript, and are immune to XSS. You can also set the Secure cookie flag to guarantee the cookie is only sent over HTTPS. This is one of the main reasons that cookies have been leveraged in the past to store tokens or session data. Modern developers are hesitant to use cookies because they traditionally required state to be stored on the server, thus breaking RESTful best practices. Cookies as a storage mechanism do not require state to be stored on the server if you are storing a JWT in the cookie. This is because the JWT encapsulates everything the server needs to serve the request.
当我读到这篇文章时,我理解带有 'state' 的 cookie 是包含有关 application/session 的数据的 cookie... 因此,包含 JWT 的 cookie 会有状态,不是吗?
此外,为什么将 JWT 存储在 cookie 中以验证 API 调用会破坏 RESTful 最佳实践?
谢谢:)
关于:
I understand a cookie with 'state' to be a cookie which contains data concerning an application/session... so therefore a cookie containing a JWT would have state, no?
cookie 的 "traditional usage" 和具有状态的服务器(通常)是 cookie 包含 session ID,并且服务器在内存中保存此 session 的详细信息是(状态,保存在服务器上)。这意味着发送到附加了 session ID cookie 的服务器的请求需要使用服务器的状态(session 中的内容)来确定要执行哪个操作或如何执行它.在这个例子中,cookie 本身通常不包含任何状态,因为它只是一个 session ID,不会在请求之间改变。
我相信您的困惑源于这样一个事实,即 JWT 会根据用户操作而改变——其中存储了一些状态——但这没关系。 RESTful 实践中的突破来自服务器存储了状态,而不是客户端发送响应请求所需的信息。
正如 Stormpath 的引述所描述的那样,将 JWT 存储在 cookie 中并不会破坏 REST 的无状态范例,因为服务器必须在每个请求上解码 JWT 并使用其中包含的数据——几乎与另一个 header 根据请求,尽管有一定的安全性。
诚然,您可以在 JWT 中存储另一个 session ID 或类似的东西,服务器可以有状态地使用它,尽管通常 JWT 倾向于包含客户端标识符或类似的东西,这是可信的由于 JWT 的签名,并基于此执行任何操作 - 服务器对请求采取行动所需的所有信息都是请求的一部分,而不是其中的一些状态存储在服务器中.
来自Stormpath:
Cookies, when used with the HttpOnly cookie flag, are not accessible through JavaScript, and are immune to XSS. You can also set the Secure cookie flag to guarantee the cookie is only sent over HTTPS. This is one of the main reasons that cookies have been leveraged in the past to store tokens or session data. Modern developers are hesitant to use cookies because they traditionally required state to be stored on the server, thus breaking RESTful best practices. Cookies as a storage mechanism do not require state to be stored on the server if you are storing a JWT in the cookie. This is because the JWT encapsulates everything the server needs to serve the request.
当我读到这篇文章时,我理解带有 'state' 的 cookie 是包含有关 application/session 的数据的 cookie... 因此,包含 JWT 的 cookie 会有状态,不是吗?
此外,为什么将 JWT 存储在 cookie 中以验证 API 调用会破坏 RESTful 最佳实践?
谢谢:)
关于:
I understand a cookie with 'state' to be a cookie which contains data concerning an application/session... so therefore a cookie containing a JWT would have state, no?
cookie 的 "traditional usage" 和具有状态的服务器(通常)是 cookie 包含 session ID,并且服务器在内存中保存此 session 的详细信息是(状态,保存在服务器上)。这意味着发送到附加了 session ID cookie 的服务器的请求需要使用服务器的状态(session 中的内容)来确定要执行哪个操作或如何执行它.在这个例子中,cookie 本身通常不包含任何状态,因为它只是一个 session ID,不会在请求之间改变。
我相信您的困惑源于这样一个事实,即 JWT 会根据用户操作而改变——其中存储了一些状态——但这没关系。 RESTful 实践中的突破来自服务器存储了状态,而不是客户端发送响应请求所需的信息。
正如 Stormpath 的引述所描述的那样,将 JWT 存储在 cookie 中并不会破坏 REST 的无状态范例,因为服务器必须在每个请求上解码 JWT 并使用其中包含的数据——几乎与另一个 header 根据请求,尽管有一定的安全性。
诚然,您可以在 JWT 中存储另一个 session ID 或类似的东西,服务器可以有状态地使用它,尽管通常 JWT 倾向于包含客户端标识符或类似的东西,这是可信的由于 JWT 的签名,并基于此执行任何操作 - 服务器对请求采取行动所需的所有信息都是请求的一部分,而不是其中的一些状态存储在服务器中.