by rvz · 7y ago · 0 comments
> A: Yes, it will be valid forever unless the server specifies an expiration time when generating it.
The implications of this is beyond calamitous. This is why Disney+ and Fortnite logins were hijacked in the first place. I can harvest all these JWT logins with a good chance of people forgetting to ever logout. Hence this, with one push of a button I can abuse an API endpoint to mass delete everybody or what not. Best part about JWTs? They are unencrypted by default.
For that reason, Just do not use JWTs.
Citation? I'm in total agreement with the problem of unexpiring tokens, but last I heard the suspected culprit in Disney+ was credential re-use. If there's newer info, I'd love to get a pointer to it.
> For that reason, Just do not use JWTs.
That seems a bit sweeping. You can apply the "unencrypted by default" dilemma to just about everything. Noting that you have to take an extra step doesn't invalidate the entire concept.
From what I can tell most people implement a blacklist of invalid tokens that need to be expired early. This isn't exactly the same as a traditional sessions table since it turns the problem on its head. You're likely to have a lower number of early expired JWTs than valid sessions.
The other way you might be able to solve this is to generate a per-user JWT key and use that to sign the JWT or embed that in the JWT. When you need to force a log out, just regenerate that value for that user.
When a client tries to use an expired JWT the request fails, and the client will then exchange the refresh token for a new JWT/refresh token pair, and finally retry the request with the new token.
The refresh operation can reject the request if the user has been deactivated (it's basically a new login request, using the expired JWT as the username and the single-use token as the password).
Presumably, the token and refresh token are both stored in the client-side app. If that gets compromised, the attacker now has the username/password combo they need to restore the session after the T+5mins has expired.
The moment you store data with Javascript it will be visible for any Javascript.
That's not a problem. It's literally how they were designed to be used: expiration time and nonces.
JWTs, like most things, work perfectly fine if implemented properly and you understand what you're doing.
Again, it's not about the tool, it's how you use it.
Just to be clear, JWT do support expiration time and nonces.
For implementations to be vulnerable, they need to intentionally avoid standard security practices.
The tool isn't the one to blame.
The right thing to do should be the easy thing to do. There's little "easy" about the "proper" use of JWT.
You're the one using JWT. You can't blame the tech if you screw up how you apply it.
> you have to ensure that the library you're using is doing sane things
Isn't this concern observed in 100% of cases where a third-party lib is used?
> The right thing to do should be the easy thing to do. There's little "easy" about the "proper" use of JWT.
That is not true at all. It's quite simple: either you know what you are doing or you develop broken software with security problems. If you decide to adopt a security technique and then fail to learn the very basics then the tech is not to blame for the problems you create for yourself.
Fernet [1] was close to being an alternative but I've seen that even Branca [2] tokens look much more like a saner alternative for replacing JWTs.
[0] - https://paseto.io
[1] - https://github.com/fernet/spec
[2] - https://branca.io
Enforced session state consistency creates a hard runtime dependency on the backend service that provides that data and that service needs to scale to handle every single client request with low latency because the token to session state lookup dictates a floor on the response time of every other service you can possibly provide.
It's not "wrong", of course lots of systems work like this, it has some advantages!
It's just a tight runtime coupling that constrains how you can scale in some ways.
The way I think about it is, if you have jwts you can always add additional "hard consistent" session state in the way you describe, but you're not forced to use it for everything.
You have options, you can make tradeoffs. And in engineering, room to make tradeoffs is a great thing to have.
As an example, with basic jwt sessions you can write say, a non-sensitive geodata lookup service for frontend (don't really care if user session is "valid" for an extra minute after "logout") in a lambda say, scale it to bejesus, but still be able to attribute requests to a user and do rate-limiting, and it has no availability dependencies on anything else.
Ok sure though, maybe change profile info (a low volume request), you need to eat a hard invalidation lookup.
Granted, its use case leans towards big systems, or systems that cross boundaries between orgs.