TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why JWTs Suck as Session Tokens (2017)

91 pointsby powvansover 2 years ago

20 comments

maxpertover 2 years ago
Yes for basic websites simple DB based session might be enough. And if you think about these sessions they are essentially opaque and stateful tokens pointing to a row in DB containing the information you need. But saying JWT sucks in plain generic terms is out of context statement, in large micro-service environment if every front-end service starts hitting an identity service the fan out is gonna kill you! You keep a basic set of information in token that is most often used, not every service will need user phone number, and all of his roles. 95% of your read traffic will need some basic ID, email, and basic roles that can be satisfied from JWT token. What OKTA is suggesting essentially is gonna push all the load onto a DB or some sort of datastore, so that it becomes SPOF, and now you have shifted problem to scaling that DB/Datastore. Answer IMO is it depends.
评论 #33064398 未加载
parker_mountainover 2 years ago
Some concepts to think about:<p>local introspection: validating the validity and lifespan of a jwt by checking it cryptographically. does not need to make a network call, thus very fast and a great way to perform a low stakes operation.<p>remote introspection: validating the integrity and lifespan of a jwt by checking with the server that signed it and&#x2F;or the server that issued the session. this should happen at least once per call flow, ideally as few times as possible but also every time sensitive information is accessed<p>if you have a heavy call graph, you can do local introspection on everything in the middle. and then, when you go to retrieve pii, do remote introspection.<p>if your token is appropriately short-lived (15 minutes), this means that an attacker can only yield information within that window with token scraping. that means that an attacker can only access data for as long as they have a foothold. i hope you have strong reporting and immutable architecture :)<p>&gt; If you’re building a simple website like the ones described above, then your best bet is to stick with boring, simple, and secure server side sessions. Instead of storing a user ID inside of a JWT, then storing a JWT inside of a cookie: just store the user ID directly inside of the cookie and be done with it.<p>so basically, if your application is doing its own authn&#x2F;authz (most monolithic applications), you don&#x27;t need jwts.
评论 #33064680 未加载
taywrobelover 2 years ago
This skips over one other big way that I’ve always seen JWT implementations fall over - sign out&#x2F;session invalidation.<p>A JWT has all the information for verifying its own lifetime contained within it, which is cool in that you don’t need to hit the DB to verify it… until you want to invalidate it before the embedded expiration is hit.<p>Then you need to hit the database or some cache layer to verify that it isn’t invalidated, and now one of the biggest reasons to use it is gone.<p>They do mention that for CRUD operations you’ll need to hit the DB anyways, which is in the same vein as this issue tho.
评论 #33063069 未加载
评论 #33084683 未加载
评论 #33063120 未加载
评论 #33063057 未加载
petrocratover 2 years ago
PASETO tokens are superior to JWT in just about every important way, it&#x27;s weird how they are so obscure and have not caught on. [1] <a href="https:&#x2F;&#x2F;paseto.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;paseto.io&#x2F;</a>
评论 #33063964 未加载
评论 #33063890 未加载
29athrowawayover 2 years ago
Also from the same author (actual titles):<p>- Multi-Factor Authentication Sucks<p>- Nobody Cares About OAuth or OpenID Connect<p>- What Happens If Your JWT Is Stolen?<p>- Why JWTs Suck as Session Tokens<p>I would rather write an article titled: Why all those blog posts suck
评论 #33063785 未加载
评论 #33064324 未加载
评论 #33064885 未加载
can16358pover 2 years ago
While I don&#x27;t necessarily disagree, I think using the globally accepted way of somehow utilizing JWTs outweigh the marginal and exaggerated (24MB for 100K requests is literally nothing in 2022) benefits.<p>If I use JWT I get widely battle tested library support and near-universal acceptance among developers, which is more than enough for most of the folks to go with JWT IMHO.
jongjongover 2 years ago
JWTs are great for fast, efficient, distributed authentication. You shouldn&#x27;t store too much stuff in the JWT, just the username and access level is generally enough. The trick is to set it to have a short expiry and keep renewing while the user is online&#x2F;active.
ChicagoDaveover 2 years ago
I’ve been building software for 35 years and web apps since “the beginning.”<p>You couldn’t drag me back to server side state management for anything.<p>OAuth2 and JWT tokens is one of best inventions and has proven itself quite thoroughly.<p>This article was goofy in 2017 and it’s even goofier now.
seandoeover 2 years ago
Jwts are great for micro&#x2F;multiple services -- no need to hit the auth db on every request.<p>Determine ttl by considering the context and then balancing performance&#x2F;security concerns.<p>If you need to invalidate a session before the ttl expires, throw the identifier in a memory cache. But I think this is overkill for most applications. Rather, protect important state changes by asking user to enter password or to provide other form of auth.<p>If the frontend wants access to the jwt data, a pattern I like is splitting the jwt by keeping the header and payload in js readable cookie or local storage, then keep the signature in an http only cookie.
Myrmornisover 2 years ago
What an awful article. Why is it talking down to their readers like that?
camgunzover 2 years ago
I found Security Cryptography Whatever&#x27;s treatment of the various session token options super informative [0]. I had some vague unformed skeptical opinions about JWTs, and now I have some reasonably informed rational opinions about them, so can recommend.<p>[0]: <a href="https:&#x2F;&#x2F;securitycryptographywhatever.buzzsprout.com&#x2F;1822302&#x2F;9020991-what-do-we-do-about-jwt-feat-jonathan-rudenberg" rel="nofollow">https:&#x2F;&#x2F;securitycryptographywhatever.buzzsprout.com&#x2F;1822302&#x2F;...</a>
somethingAlexover 2 years ago
&gt;&gt; “ A mission critical user check needs to run (eg: does this user have enough money in their account to complete the transaction?)”<p>That info wouldn’t be in the session db row either.<p>&gt;&gt; “ A database write needs to occur to persist information (if this information is related to the user, it’s likely that the full user object must also be retrieved from the database”<p>This type of info doesn’t get updated frequently. Email, phone, name, etc, are pretty static. If they are just talking about a join using a userId, well that’s not gonna be any different whether you know the ID from a JWT or normal cookie.<p>&gt;&gt; “ The full user object must be pulled out of the cache &#x2F; database so that the website can properly generate its dynamic page content”<p>But that’s an upside of keeping more than a cookie with an ID. You can just stash the stuff that doesn’t change much client side (keeping in mind the XSS risks). We certainly don’t pull the user’s email and name every page load even though it’s displayed on every page.<p>&gt;&gt; “ Almost every web framework loads the user on every incoming request. This includes frameworks like Django, Rails, Express.js”<p>That’s a framework issue and should be customizable. Not really a JWT vs cookie w&#x2F; ID topic<p>There’s plenty of reasons to choose an ID cookie vs a JWT but the many that the author gives are not among them.
sgammonover 2 years ago
JWTs survive in popularity because, by and large, their size is negligible over the wire, internet speeds get faster (not slower), and key agreement across systems is still a surprisingly complex problem.<p>(1) Size Factoring Gzip and HTTP&#x2F;2 header compression into this, size is no longer an issue, but it&#x27;s still a reasonably good idea to keep claim sizes down. If you don&#x27;t like using cookies, use a sessionStorage value and affix via XHR! Easy<p>(2) You&#x27;re Going to Hit The Database Anyway No you aren&#x27;t, necessarily? Wth. Also, JWKS paired with JWT gives fantastic rotation security with very minimal configuration across systems. So, maybe you don&#x27;t even <i>have</i> the database accessible to you. You can still verify your signatures.<p>(3) Redundant Signing Sounds like this is advice for some framework that signs the session cookie? This is silly.<p>&quot;You should use Session IDs instead&quot;<p>Tell me you haven&#x27;t built a globally distributed system without telling me you haven&#x27;t built a globally distributed system.
评论 #33063913 未加载
kache_over 2 years ago
JWT as a term used to describe signed material should considered harmful (source: me)<p>It&#x27;s basically just signed authentication material<p>Use it when you need to keep your authentication layer horizontally scalable &amp; stateless<p>Use it when you&#x27;re transferring trust to an untrusted system, acting on behalf of a user (SAML, OAuth, OIDC)<p>that&#x27;s it<p>It&#x27;s just signed material<p>data size limitation (from the blog) is a big meme (source: me). Just pack it into a protobuf lmao<p>eventual consistency of a stateful session will hurt you btw<p>yes yes yes I know. The grey bears gave us protocols, rfcs, etc. MUH PROTOCOLS. just give me a private key and a bud light dude<p>the protocols are important for oidc&#x2F;oath&#x2F;saml<p>JWT ISN&quot;T A PROTOCOL<p>i&#x27;m tired, I should go sleep
senkoover 2 years ago
Related recent discussions (different articles on a similar topic):<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=33019960" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=33019960</a><p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=33018135" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=33018135</a>
sascha_slover 2 years ago
&gt;In this case the requesting party will have a token to prove their identity, and can forward it to the third (or 4th … nth) service without needing to incur a real-time validation each and every time.<p>Someone missed the entire point of audience claims in OIDC - on okta.com no less.
senkoover 2 years ago
Randall has also given a number of talks on the topic, so if you prefer watching to reading, have a look at <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=JdGOb7AxUo0" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=JdGOb7AxUo0</a>
shp0ngleover 2 years ago
At this point, JWTs are a cargo cult. People do them because everyone else does them, even when it makes 0 reasons in the app itself and they use them as worse session tokens.<p>Nobody was ever fired for using JWT for authentication.
woileover 2 years ago
Has anyone tried <a href="https:&#x2F;&#x2F;www.biscuitsec.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.biscuitsec.org&#x2F;</a> ?<p>I haven&#x27;t seen it much discussed, and seems to solve a lot of issues from JWT
sgammonover 2 years ago
This was definitely written pre Auth0 acquisition, just saying