News for hackers. Stuff that matters.
Re:Anatomy of a JWT by mooreds on Tuesday March 01, 2022 @05:04PM (#30520677)
> especially if you make your tokens long-lived

Agreed! You should never make tokens long lived. Seconds to minutes is what we typically see.

"But won't users have to log in whenever the token expires?" Nope, that's what the refresh grant (in the OAuth world) is for. I am not as familiar with other uses of JWT, but I suspect there is a similar process that relies on the issuer for them.

> But at that point, it's no longer stateless.

Agreed, it is an architectural choice. You can choose the benefits of statelessness (scale) at a cost of revocation difficulties. You can get revocation, but you have to re-introduce state.

Is there some token solution out that that I'm unaware of that gives you statelessness and revocation? Would love to learn more about it if so.

Re:Anatomy of a JWT by tptacek on Tuesday March 01, 2022 @07:18PM (#30521917)
The refresh grant is itself a long-lived, difficult-to-revoke token. TANSTAAFL.
Re:Anatomy of a JWT by mooreds on Wednesday March 02, 2022 @02:05PM (#30531375)
How are refresh tokens difficult to revoke?

They are presented to the AS to get a new access token, and the AS has pretty good insight into whether a user is logged in or signed out, right?

Re:Anatomy of a JWT by daveidol on Tuesday March 01, 2022 @07:36PM (#30522063)
Just like a session cookie is long-lived? At least with a refresh token you can keep things like specific roles etc. out of it and treat it much like an opaque session cookie (perhaps just containing nothing but the user's ID, which can be looked up to get the real roles/permissions for the short-lived access tokens).

I think it's dubious to call refresh tokens "difficult-to-revoke" but call sessions easy to revoke. Both require some kind of state. The difference is that you are (hopefully) doing far more grants and checks on tokens than you are doing revokes - so why not optimize for that flow?

Re:Anatomy of a JWT by tptacek on Tuesday March 01, 2022 @07:57PM (#30522248)
Session cookies are generally server-side stateful and trivially revoked, which is why we don't worry as much about their lifespan. JWTs are generally stateless --- that's one of their top-promoted features --- and are, in fact, difficult to revoke.
Re:Anatomy of a JWT by daveidol on Wednesday March 02, 2022 @08:36PM (#30536007)
I still don't see how this makes it significantly more difficult to manage or revoke a JWT than a server-side session. For the session you remove it from the DB, and with a JWT you add it to a blacklist.

About the same amount of effort from my perspective, and revokes are probably extremely rare by comparison to issues or validations of tokens/sessions...

Re:Anatomy of a JWT by JamesSwift on Tuesday March 01, 2022 @08:58PM (#30522733)
Session cookies are just a password for the server to lookup the information _on its side_. So when you revoke the server's portion of the session, it no longer exists even though the cookie is "valid".
Re:Anatomy of a JWT by daveidol on Wednesday March 02, 2022 @08:38PM (#30536025)
Right, I understand that. JWTs can be revoked using a similar server-side mechanism - just that it's more of a blacklist instead of a whitelist.

And since you are likely adding more sessions than you are manually revoking them, why not optimize for that flow and use JWTs? Sure they may not be 100% stateless if you have to maintain the blacklist, but I'd say 99.9% stateless is still preferable over 0% stateless for many applications.

Re:Anatomy of a JWT by davorak on Saturday March 05, 2022 @08:00PM (#30573837)
The main advantage of JWT, at least the advertisement historically, has been they are stateless and scalable, but that black list makes the system stateful again and you loose out on most(or all scalability) benefits. I think how much you loose depends on the specifics of the implementation, you definitely seem to loose any simplicity of design though from what I have read/worked with.
Re:Anatomy of a JWT by e12e on Wednesday March 02, 2022 @02:20PM (#30531587)
Yes, but also no. Typically you might need a valid jwt on every request, but a refresh token request on a different (hot) path only every 5 minutes per user. And revalidation might easily query a whitelist (sql/db - is user valid for login/refresh) or a blacklist (is refresh token invalid?).

The jwt being valid 10 minutes (accounting for clock drift) might be a problem - but probably sufficient for many applications?