News for hackers. Stuff that matters.
Re:JWT should not be your default for sessions by jakelazaroff on Wednesday May 12, 2021 @09:48PM (#27137538)
That's exactly the same as checking a list of tokens. If you need to make a DB trip on every request, what advantage are you getting from JWTs?
Re:JWT should not be your default for sessions by Alex3917 on Thursday May 13, 2021 @08:18AM (#27141253)
> If you need to make a DB trip on every request

There's no extra DB request, assuming you need to lookup the user model on each request already.

Re:JWT should not be your default for sessions by jakelazaroff on Thursday May 13, 2021 @09:26AM (#27141808)
In that case, you can avoid DB overhead by joining the user when you query the session. I'm still not sure what advantage JWTs have in this scenario.
Re:JWT should not be your default for sessions by spookthesunset on Thursday May 13, 2021 @12:05AM (#27138274)
> If you need to make a DB trip on every request, what advantage are you getting from JWTs?

Because you don't need to check the DB every request! That's the cool part! You only hit the DB for requests that matter!

For example, do you really need to check the DB to load this very page? If the auth token expiration is say, 5 minutes... does it really matter if a bad guy gets ahold of that token and loads this page? They can't post or vote because for those requests... you can pass the token to your auth server to be validated. 99% of your traffic is probably servicing the loading of this very page. 1% (or probably closer to 0.1%) is any kind of traffic that you actually care if the token hasn't expired within 5 minutes.

The problem people get into is they think security is black and white. It's gray. Some things need to trade latency for security... like write traffic. For 99% of the read traffic on HN? Who cares... even 10 minutes or more might be okay depending on the business.

People invent these complex pub-sub systems and stuff... they are working under the idea that all requests need to be super-secure. Most of it doesn't. I'd assert for most businesses.... 99% of the authenticated traffic could deal with a 5 minute max window after logout where somebody could maybe, theoretically impersonate somebody. And for the 1% of that traffic where it matters, you can always hit the DB.

Re:JWT should not be your default for sessions by kalleboo on Thursday May 13, 2021 @09:15AM (#27141698)
> I'd assert for most businesses

"for most businesses" you're never going to have enough traffic that a classic session database (even stored in, gasp, MySQL) would be a bottleneck.

JWT definitely has it's places but it has so much complexity, so many tradeoffs and footguns that it should only be used when you have a specific problem with a standard session system that you need to solve, not as the default.