News for hackers. Stuff that matters.
Re:Ask HN: What's the current sentiment on JWT for stateless... by jchw on Friday December 13, 2019 @02:23PM (#21784507)
To be clear though you generally set the validity to be relatively short and refresh often, so that way you don’t have to worry too much; you can then “revoke” a token by refusing to refresh it.
Re:Ask HN: What's the current sentiment on JWT for stateless... by 3pt14159 on Friday December 13, 2019 @02:35PM (#21784614)
But then it isn't stateless, right? Because you need to know which current tokens are unrefreshable.

To me, JWT works great for things like physical people getting access to a physically isolated building, like a military research site that's disconnected from the internet. Some secure other place holds the private key and signs the JWT token then you can wave in anywhere you need to go until the validity period is up. Then you have to go back to the secure place to get a new key, verifying the same way you did the first time and the secure place can broadcast its public key to the sites you want access to. It's essentially a great mechanism where you don't have constant communication links.

But I just don't get it for servers. Also, everyone considering using a JWT token should know about the "algorithm none" setting and ensure that their stack isn't vulnerable to it.

Re:Ask HN: What's the current sentiment on JWT for stateless... by bgentry on Friday December 13, 2019 @02:40PM (#21784643)
But then it isn't stateless, right? Because you need to know which current tokens are unrefreshable.

You only have to involve state in 1 request every 10-15 minutes upon refresh. All other requests can be done without having to check for revocation. This is a pretty nice real-world tradeoff.

Re:Ask HN: What's the current sentiment on JWT for stateless... by abathur on Friday December 13, 2019 @03:02PM (#21784856)
While I haven't taken the leap to using a JWT in any of these cases yet and am a little bearish on them, I do also feel like the baby goes out with the bath-water, here.

Nothing about adopting JWT says you can't still use a full auth check for state-changing endpoints, and use a stateless session to shave some evaluation time off of frequent read-only requests for data that isn't terribly sensitive.

You probably shouldn't do it lightly or prematurely since it makes it harder to reason about authentication, but I think it's worth considering whenever you're optimizing.

Re:Ask HN: What's the current sentiment on JWT for stateless... by jchw on Friday December 13, 2019 @02:47PM (#21784724)
Actually creating a JWT token is not stateless, but at least your architecture is not centralized. If your auth server goes down, that’s a problem no matter what.

A common validity period is around 1 hour, which is good enough that most users won’t need to refresh very many times per day.

Also: you don’t necessarily need to track tokens that aren’t refreshable. A typical architecture might have a timestamp stored per user that specifies the earliest token creation date that’s valid for refresh. That way you can invalidate all tokens without needing to ever store them; something you might need to do for password reset, for example.

Re:Ask HN: What's the current sentiment on JWT for stateless... by xvector on Friday December 13, 2019 @08:12PM (#21787116)
> A typical architecture might have a timestamp stored per user that specifies the earliest token creation date that’s valid for refresh.

Never worked with JWTs but still, can't believe I didn't think of this. It seems like a fairly elegant way to revoke things where your only stored state is a timestamp.

Re:Ask HN: What's the current sentiment on JWT for stateless... by kelnos on Saturday December 14, 2019 @02:29AM (#21788311)
> A typical architecture might have a timestamp stored per user that specifies the earliest token creation date that’s valid for refresh.

There's a race condition there, though. If you have a revocation event and set the timestamp, it's possible that an in-progress refresh might have a timestamp just slightly after your stored timestamp. Then you have a rogue JWT that can continue to be refreshed.

Clocks are sometimes not in sync with millisecond precision. Databases don't replicate instantly. Distributed systems just don't work that way.

Re:Ask HN: What's the current sentiment on JWT for stateless... by JamesSwift on Saturday December 14, 2019 @09:42AM (#21789703)
You could instead store a "generation", and increment on revocation events
Re:Ask HN: What's the current sentiment on JWT for stateless... by wruza on Saturday December 14, 2019 @11:32AM (#21790312)
>algorithm none

I just read about it on Auth0 [0] and facepalmed. Then I went to node-jsonwebtoken to ensure they added an ‘algorithm’ argument to a ‘verify’ call and you guess what [1].

They added ‘algorithms’, but into ‘options’, so that naive user like me could just skip it and stay open to attacks. That’s auth0’s own module, btw.

Thanks for pointing that out!

[0] https://auth0.com/blog/amp/critical-vulnerabilities-in-json-...

[1] https://www.npmjs.com/package/jsonwebtoken#jwtverifytoken-se...

Re:Ask HN: What's the current sentiment on JWT for stateless... by pfohf on Saturday December 14, 2019 @01:24PM (#21791108)
Use a proper JOSE module like https://www.npmjs.com/package/jose that uses native node's crypto key objects (ergo not leaving you vulnerable to HMAC based validation bypass) and doesn't even implement "none" algorithm.
Re:Ask HN: What's the current sentiment on JWT for stateless... by blackflame on Friday December 13, 2019 @02:42PM (#21784676)
You always have to authenticate the JWT anyways to verify data hasn't been changed. The stateless part is the fact that the sensitive data is stored in the JWT itself instead of retrieved from a DB. As long as you can validate the HMAC / Signature then you can assume the contents of the JWT haven't been altered and can therefore trust the client's data.
Re:Ask HN: What's the current sentiment on JWT for stateless... by aaomidi on Friday December 13, 2019 @02:48PM (#21784740)
Authenticating JWT isn't checking the JWT against an external server.
Re:Ask HN: What's the current sentiment on JWT for stateless... by blackflame7000 on Friday December 13, 2019 @03:25PM (#21785074)
How can you validate that it was properly signed without comparing it to the entity's public key?
Re:Ask HN: What's the current sentiment on JWT for stateless... by cstrahan on Friday December 13, 2019 @04:05PM (#21785457)
Why would you need to make a request to another server for this purpose?

Hint: you don’t — but I figure taking the Socratic approach may be more convincing.

Re:Ask HN: What's the current sentiment on JWT for stateless... by rblatz on Friday December 13, 2019 @04:30PM (#21785709)
You could pre share a public key, but a common way is to use the discovery mechanism in OIDC to automatically manage key distribution/rolling.
Re:Ask HN: What's the current sentiment on JWT for stateless... by blackflame on Friday December 13, 2019 @07:46PM (#21787008)
Because else how do you handle key revocation?
Re:Ask HN: What's the current sentiment on JWT for stateless... by aaomidi on Friday December 13, 2019 @11:32PM (#21787826)
Which is the point of the post.

If you need to do revocation you need to call an external server.

If you need to call an external server why do JWT?

Re:Ask HN: What's the current sentiment on JWT for stateless... by blackflame on Saturday December 14, 2019 @04:19PM (#21792329)
Because pinging another server for a few bytes of data and offloading that working memory to the client side is much more efficient than storing the session data in server memory in between requests. Furthermore a single coordinating key server can work in conjunction with many micro-services to simplify architecture, security, and hardware requirements.
Re:Ask HN: What's the current sentiment on JWT for stateless... by altmind on Saturday December 14, 2019 @03:14PM (#21791887)
Which still leaves a window for JWT to be re-played. If you store something valuable, like # of credits left on a users account, the user can spend some, and then re-use an old jwt to spend again.
Re:Ask HN: What's the current sentiment on JWT for stateless... by closeparen on Friday December 13, 2019 @06:24PM (#21786568)
It’s stateful for the auth service, stateless for the relying party.
Re:Ask HN: What's the current sentiment on JWT for stateless... by jayd16 on Friday December 13, 2019 @02:28PM (#21784551)
The link seems to think this is impossible but I don't understand why.
Re:Ask HN: What's the current sentiment on JWT for stateless... by jchw on Friday December 13, 2019 @02:49PM (#21784750)
Don’t see the word “refresh” in there. Guessing they are assuming you use JWT identically to how you might use a session cookie, which is not how I’ve ever seen it used, personally.
Re:Ask HN: What's the current sentiment on JWT for stateless... by jayd16 on Friday December 13, 2019 @03:39PM (#21785214)
In the diagram in the bottom right they seem to think you cannot revoke the long term token. I agree that it doesn't align with my understanding of whats capable with oauth2 style tokens, for example.
Re:Ask HN: What's the current sentiment on JWT for stateless... by cstrahan on Friday December 13, 2019 @04:28PM (#21785688)
That box should probably read: “You can't revoke the long-term tokens in a stateless manner, so supposing you truly manage ZERO state, then you're back to square one.”

That seems like the charitable interpretation. Note that the author’s point has not been that JWT is useless, but rather that trying to use stateless JWT for sessions is a bad idea.

If the point of using for JWT was to avoid all server side state in authn/authz flow — which is the case for many, many developers, and that is the intended audience of the author’s post — then one of two things: you either contradict yourself and implement server side revocation for refresh tokens, or you let the lifetime of your sessions be the same as the refresh token — and in the case of refresh tokens with no expiry, the user (or anyone with their refresh token) can stay logged in forever.