Invalidating client side JWT session

Blacklists are a JWT stateless violation. There is a lot of authentication schemes which you may use. JWT is based on stateless so it should be used that way. On the other hand, it is very common authentication scheme and if you have to implement it, and if you want your application (API) to be truly secure, some customisation must be allowed.

I personally use this two methods on my projects (separate or combined, depending on performance needs):

  1. Tokens Log. I do log every token issued in my project, with ID, claims, expiration and I do validate it on each request. If token is expired, it will be moved from this log to archive. Performance drop is not that awful.

  2. I also add to claims in addition to user's name a hash of user's secret (something like autogenerated hidden token or password) which is authorized in next step when loading user from dbo. This has no significant performance drop because the query for user is performed anyway. Drawback is that you may not invalidate concrete token, only all user's session.


I've done some homework and seems that the better approach to implement the revocation is to use jti (id on Jtw) and a blacklist of revoked id (wich will be cleared when the token is expired). This make the JTW stateful for the only the blacklist part.


There are several reason to invalidate a JWT token before its expiration time: account deleted/blocked/suspended, password changed, permissions changed, user logged out by admin. So your question is on topic

There are several techniques to apply or combine depending on your use case

1) Remove the client token from local storage

2) Token blacklist: Store tokens that were between logout & expiry time, mark expired and check it in every request. Use a unique identifier jti or include last login date and issued at iat to remove old tokens

It is needed server storage. If you do not expect too many tokens to revoke, you also could use an in-memory blacklist. You only need to set an entry after updating critical data on user and currentTime - maxExpiryTime < lastLoginDate (iat)‌​. The entry can be discarded when currentTime - maxExpiryTime > lastModified (no more non-expired tokens sent). In this case is not needed to store the entire token. Just sub, iat and maybe jti

3) Expiry times short and rotate them. Issue a new access token every few request. Use refresh tokens to allow your application to obtain new access tokens without needing to re-authenticate and combine with sliding-sessions

Sliding-sessions are sessions that expire after a period of inactivity. When a user performs an action, a new access token is issued. If the user uses an expired access token, the session is considered inactive and a new access token is required. This new token can be obtained with a refresh token or requiring credentials

Other common techniques

  • Allow change user unique ID if account is compromised with a new user&password login

  • To invalidate tokens when user changes their password, sign the token with a hash of their password. If the password changes, any previous tokens automatically fail to verify. Extend this mechanism with other field of interest to sign. The downside is that it requires access to the database

  • Change signature algorithm to revoke all current tokens in major security issues

Take a look at Invalidating JSON Web Tokens