Starting from the bottom, I would ignore update tokens, since I don't think they will help you. They tend to target other scenarios in which a client application can provide more secure storage than a user browser — I think native mobile applications or server-side web applications.
Update tokens are durable . This means that when a client receives one server, this token must be securely stored so that it is not used by potential attackers, for this reason it is not safe to store them in a browser.
(emphasis mine source update tokens )
This means that option 2.3 is basically the same as 2.2, which is not a bad option. It is not uncommon to have web applications with a long session duration. If your application is not very sensitive, it is recommended to use a long session to improve the user experience. For example, Django uses a default of two weeks for the age of its cookie session. See SESSION_COOKIE_AGE .
The remaining option (2.1) is usually called a rolling session. The session timeout is short, but as long as the user continues to use the application during this interval, the session is automatically updated. Perhaps this is the most common approach, or at least the one that I have used most of the time, so I am biased. The only thing I would like to point out is that a rolling session is usually implemented with opaque session identifiers stored on the client side as cookies, and then with the actual session data stored on the server.
Your approach is slightly different since you have a stateless JWT token (it contains the actual user data) stored in the local storage of the browser. As you said, in order to update a token, you will have to generate a new one because you will need to generate a new signature.
The signature is used to verify that the sender of the JWT is the one who says it is , and to ensure that the message has not been changed in transit.
(emphasis mine, source of JSON tokens )
Having said all this, I would consider the following:
- Ask yourself if you really need JWT, or if regular session identifiers stored as cookies ( HTTP only ) will simplify your logic.
- If the JWT is a requirement, for example, you have another API that will also accept these tokens as authentication, then I would consider option 2.1 or 2.2, since update tokens are not recommended for a browser-based application.
Having said that, you should also bear in mind that JWTs are not huge, but they will still be overhead if you decide to automatically renew. You can mitigate this a bit by choosing a session duration of 20 minutes and do an automatic update after half the session.
Another point is that a vulnerability, such as XSS in your application, will output an access token to an attacker, since the entered scripts can be read from localStorage / sessionStorage , this could be another point in favor of only HTTP session cookie storage.