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.

Should I use JWTs for authentication tokens?

577 pointsby pantalaimon12 months ago

84 comments

jupp0r12 months ago
&quot;Just use the normal session mechanism that comes with your web framework and that you were using before someone told you that Google uses jwt. It has stood the test of time and is probably fine.&quot;<p>You don&#x27;t need to be Facebook or Google to have more than one service in your infrastructure that needs to authenticate a user&#x27;s existing session without forcing the user to log in again. Sharing the session across multiple services is its own distributed systems problem with numerous security implications to be aware of and bearer tokens might be a good alternative.<p>If all you have is a single monolith web app that is the identity provider, makes all authentication decisions etc then yes, you don&#x27;t need JWTs probably. There is a huge gap between that and being Google&#x2F;Facebook.<p>Apart from that, Google and Facebook don&#x27;t even use JWTs between the browser and backends after the initial login but actually do have some sort of distributed session concept last time I checked.
评论 #40494614 未加载
评论 #40493945 未加载
评论 #40500226 未加载
评论 #40497126 未加载
评论 #40498296 未加载
评论 #40503234 未加载
评论 #40497182 未加载
评论 #40496316 未加载
评论 #40497738 未加载
davedx12 months ago
Okay I&#x27;ll bite...<p>This post doesn&#x27;t seem to address microservice architectures at all? For me, this is the primary reason to use JWT&#x27;s -- so you can pass authentication (&quot;claims&quot;, or whatever you want to call them) through your chain of microservice service-to-service calls. If you don&#x27;t have microservices then there&#x27;s much less reason to use JWT&#x27;s.<p>I&#x27;m not saying the article is a strawman exactly, but it does seem to miss the primary use case of JWT&#x27;s. At least, the way I&#x27;ve used them in anger.<p>Also, the &quot;JWT&#x27;s can be insecure if you use the wrong library or configure them incorrectly&quot; argument, while having <i>some</i> points, seems to me more of an argument that you should really do due diligence on any libraries you use for security. The better JWT libraries are not insecure by default.<p>I wouldn&#x27;t use JWT&#x27;s if I were making a monolith, but there are lots of companies who (for better or worse) use microservices.
评论 #40492189 未加载
评论 #40493711 未加载
评论 #40492199 未加载
评论 #40493527 未加载
评论 #40492641 未加载
评论 #40496313 未加载
评论 #40493383 未加载
评论 #40494813 未加载
oppositelock12 months ago
JWT&#x27;s are perfectly fine if you don&#x27;t care about session revocation and their simplicity is an asset. They&#x27;re easy to work with and lots of library code is available in pretty much any language. The validation mistakes of the past have at this point been rectified.<p>Not needing a DB connection to verify means you don&#x27;t need to plumb a DB credentials or identity based auth into your service - simple.<p>Being able to decode it to see its contents really aids debugging, you don&#x27;t need to look in the DB - simple.<p>If you have a lot of individual services which share the same auth system, you can manage logins into multiple apps and API&#x27;s really easily.<p>That article seems to dislike JWT&#x27;s, but they&#x27;re just a tool. You can use them in a simple way that&#x27;s good enough for you, or you can overengineer a JWT based authentication mechanism, in which case they&#x27;re terrible. Whether or not to use them doesn&#x27;t really depend on their nature, but rather, your approach.
评论 #40498174 未加载
zemo12 months ago
External services use jwts pretty often, so if you have to handle jwts anyway, using jwts means that there&#x27;s only one primitive, set of libraries, and concepts for your devs to know.<p>&quot;You don&#x27;t need all of that!&quot; sure but you probably already <i>have</i> it somewhere in your codebase and it&#x27;s pretty universal. You also probably don&#x27;t utilize every feature of http itself, that isn&#x27;t a cogent argument against using http.<p>JWTs are supported by a large number of tools, libraries, middleware appliances, etc; there&#x27;s a huge ecosystem out there to support it.<p>You also might delegate auth to a third party like Auth0 or FusionAuth so that you don&#x27;t handle <i>any</i> PII, because all of the PII is handled by a vendor, and you only store application-specific data.<p>&quot;You want to implement logout&quot; means a few things; in most apps you just ... have the client forget the token and you go about your day and it&#x27;s fine. &quot;but what about if a nefarious actor stole the token!!!&quot; you might say, but hand-rolled session tokens have the same problem.<p>&quot;You want to turn off access for all users&quot; is something you can do in http middleware; e.g., I have used middleware that do things like &quot;only allow through requests that have jwts with the &#x27;admin&#x27; role in their claims because we have turned off the system from users for downtime&quot;, and that works fine. (specifically I wrote a traefik plugin to do this in an afternoon).<p>&quot;You want to ban a single specific user really quickly&quot; is a thing JWT won&#x27;t do out of box.
评论 #40492719 未加载
aranchelk12 months ago
Even running in smaller environments:<p>1) You may not want your application servers having direct access to your auth service or auth database. You may not have the resources to control employee access to sensitive data when it’s shared across services. You may want to spend limited resources for security audits on the systems that contain the most sensitive data, and having them separated from everything else is helpful.<p>2) Depending on what 3rd party services you use it may not even be practical to have connectivity between auth and other services, and if you do, the latency may be bad enough that you wouldn’t want it to be blocking every request. This is especially compelling for hybrid environments, e.g. the 20 year old database in a colo with your user data, and a new service being built for you by consultants on a PaaS.<p>3) People act like revocation is such a nightmare, but you only need the auth service to sign invalidation tokens to be passed to the client-facing services, and those services only need to retain them for the max TTL of the auth tokens, after which they can be evicted. Yes, that’s something that could be motivated by having a massive environment like Google, it could also just be a way to keep costs down when you’re paying by the byte of storage or by the outbound request on some cloud. You could try to make the argument that storing invalidation data is just as bad as storing session data, but the key questions are “Where?” and “For how long?”, and then in some circumstances it breaks down very quickly.<p>4) You may not want sensitive user data stored in the jurisdictions where you want to host your apps. That’s not a big company problem, it’s dependent on the nature of the services you provide.
teliskr12 months ago
Some people get entirely too dogmatic about their “XYZ is wrong, don’t do it!” beliefs. At the time I implemented JWT in our system, many years ago; it was the most straightforward way to solve the problems that I had. I read about the pitfalls and have yet to experience any of them. So in short.. “no regrats” from this heathen.
评论 #40505942 未加载
unscaled12 months ago
Here&#x27;s the thing: neither Google, nor Facebook is using JWT for their access or refresh tokens. The only place they use JWT, as far as I know, is for the ID Token in their Open ID Connect Flow, since this is a mandatory (and terribly misguided) part of the spec.<p>I keep seeing the idea that JWT was designed for Google or Facebook scale being repeated over and over, but the reality is that neither company uses it. Last time I checked, both used rather short access and refresh tokens and it appears that at least the refresh token (if not both) is stateful.<p>Implementing stateful tokens on a global scale and sharing them across hundreds of service is HARD, but it&#x27;s easier when you are Google or Facebook, and you&#x27;ve got enough resources to throw at this trouble.<p>And if you do need to implement a stateful token, you&#x27;ve got every reason to choose your own format. Your applications are using your own authentication libraries and infrastructure (e.g. API gateways), so you don&#x27;t have to worry about complicating their life with a non-standard format. The upside for using your own stateless format is that you avoid all the design issues with JWT (alg=none, algorithm confusion, questionable support for outdated algorithms from the 1970s) and you can design a far more compact format that takes a fraction of the size of JWT[1].<p>There&#x27;s a reason JWT got popular with scrappy startups, enterprises hobby projects and Udemy&#x2F;Medium tutorial authors: they&#x27;re very easy to spin up and library support is everywhere. I don&#x27;t mean to say JWT is the right choice for any of these uses — it probably isn&#x27;t. But it&#x27;s the easy choice, the worse-is-better solution. The worse solution needs only be better in one respect to win: it should be easier to implement, copy and spread.<p>In the end of the day, JWT is not a good solution for either Google-scale companies or small startups. But it&#x27;s the small startups that usually lack the resources and awareness to adopt another solution.<p>[1] <a href="https:&#x2F;&#x2F;fly.io&#x2F;blog&#x2F;api-tokens-a-tedious-survey&#x2F;#protobuf">https:&#x2F;&#x2F;fly.io&#x2F;blog&#x2F;api-tokens-a-tedious-survey&#x2F;#protobuf</a>
EthanHeilman12 months ago
&gt; By just using a “normal” opaque session token and storing it in the database, the same way Google does with the refresh token, and dropping all jwt authentication token nonsense.<p>Not only is this true, but most actual deployments of JWTs just have you swap a JWT (ID Token) for a opaque session token.<p>That said, I really like having a JWT signed by an IDP which states the user&#x27;s identity because if designed correctly you only need to trust one party IDP. For instance Google (the IDP) is the ideal party to identify a gmail email address since you already have to trust them for this. I created OpenPubkey to leverage JWTs, while minimizing and in some cases removing trust.<p>OpenPubkey[0, 1] let&#x27;s you turn JWTs bearer tokens into certificates. This lets you use digital signatures with ephemeral secrets.<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;openpubkey&#x2F;openpubkey">https:&#x2F;&#x2F;github.com&#x2F;openpubkey&#x2F;openpubkey</a> [1]: <a href="https:&#x2F;&#x2F;eprint.iacr.org&#x2F;2023&#x2F;296" rel="nofollow">https:&#x2F;&#x2F;eprint.iacr.org&#x2F;2023&#x2F;296</a>
评论 #40496286 未加载
评论 #40495970 未加载
bebop12 months ago
I would add two pros of jwts (I guess oauth 2 and oidc more specifically)<p>1. It standardizes your auth system. While sessions auth is mostly implemented in the same way across systems, learning oauth and oidc gives you a standard across the industry.<p>2. Jwts give an easy path to make “front end” applications and api authentication work in the same way. This in theory reduces your security surface area as all of your authnz code can be shared across your offerings.
评论 #40492535 未加载
评论 #40504404 未加载
评论 #40497356 未加载
apatheticonion12 months ago
I typically use a service like AWS cognito (using their built-in hosted UI) to handle authentication for my apps. That gives me MFA, Google&#x2F;Facebook login, email verification, etc for free and has a generous free tier.<p>I have a template that&#x27;s backed by terraform and the authentication client is in lambda so the whole thing is serverless, self-contained and practically free. So I just run &quot;terraform apply&quot; and I have scalable auth for my new service.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;alshdavid&#x2F;template-cognito">https:&#x2F;&#x2F;github.com&#x2F;alshdavid&#x2F;template-cognito</a> (only 1 dependency on AWS, everything else is stdlib)<p>If any service I create is lucky enough to break out of the free-tier and cost is an issue, then I can just move to another OAuth2&#x2F;OIDC provider. The auth mechanism Cognito uses is just a specification meaning I am not coupled to any one service provider (though the user accounts themselves are). Cognito, Auth0, IdentifyServer, or whatever - I can migrate if cost becomes a problem.<p>The big issue with JWTs are that, if lost, they give permissions to attackers without revocability.<p>For this reason, I keep auth-tokens short lived and refresh them often. Refresh-tokens are revocable and live for a few days. This means that a lost auth-token is only harmful for a few minutes while a lost refresh token is only harmful until revoked or expired.<p>Tokens are stored as path-specific http-only cookies so the only vector for attack is if a user physically opens devtools and gives an attacker the token - or if the attacker has access to the computer (physically or via a malicious terminal script).<p>High risk operations (e.g. delete account, delete content, anything high risk) requires &quot;step-up&quot; authentication - so a user is asked to re-authenticate in those cases.<p>Overall, when you consider that rolling your own authentication comes with the liability associated with holding user data (companies must announce a breach to users, etc) - if a service provider like Cognito is compromised, you won&#x27;t be liable or the only one affected.<p>JWTs have security concerns, but on balance, when used with third party provider, a sensible configuration and considering the risk of rolling your own - they are fine.
jameshart12 months ago
Browser sessions are not the only authentication scenario.<p>&gt; absolutely no one who is not Google&#x2F;Facebook needs to put up with the ensuing tradeoffs. If you process less than 10k requests per second, you’re not Google nor are you Facebook<p>What&#x27;s the magic property that flips when you pass 10K requests per second? Are we sure it&#x27;s at 10K requests per second, not 8K? or 5K? In general, at that kind of scale I&#x27;d think JWTs would become less appealing - AWS operates on IAM for example.<p>And why are Google and Facebook the best examples of companies who are operating at scale? There are different kinds of scale than just &#x27;ad auctions per second&#x27;. I would imagine the access management concerns of, say, JP Morgan Chase are at least as complex and challenging to scale as those of Facebook.
评论 #40492286 未加载
评论 #40494025 未加载
menacingly12 months ago
We don&#x27;t use JWTs because we think we&#x27;re google scale, we use them because they&#x27;re kinda cool. Cheap, stateless auth across services is really handy. If I rolled my own solution, it would just look like a shitty jwt.<p>There are definitely arguments to me made against ridiculous over-engineering, modern web dev has taken the problems of 1% of engineers and made them problems for 100% of engineers, but I think this is a bit of a silly one to focus on
评论 #40496604 未加载
tracker112 months ago
Authentication is often the first thing I want to break out of the application and backend anyway. Good password hashing is expensive... Why should an entire application have to go down when your login is being DDoSed?<p>More so, A revocation list on something like Redis can expire with a token and a lot less expensive than an rdbms lookup with joins.<p>Not too mention, why add extra load with extra DB calls in the first place?<p>You don&#x27;t have to be Google scale to want to separate logins from the main service. And that&#x27;s just for starters.
jurassic12 months ago
The more confidently people make blanket pronouncements, the less you should believe them. There are a lot of use cases for OAuth2 and OIDC that are not covered by “just use a web session”.<p>The real thing to push back on is the logout requirement. Everyone pretends they need this, when what almost everyone should do is just mandate appropriately short token lifetimes and revoke refresh tokens as needed.
评论 #40496161 未加载
评论 #40503683 未加载
rezonant12 months ago
Since JWTs can&#x27;t handle revocation on their own, the main benefit (other than the ability to do validation without a central authority) of JWTs over opaque tokens is the ability to embed data that an untrusted holder (ie client) can make use of. For example, attach the display name of the user and their avatar profile, so that even after the token expires the application can represent to the user who the token is (could be used for example to show a &quot;Sign back in, Tom&quot; view). This makes a Switch User feature very elegant to implement: the application need only store the signed authentication tokens, and those tokens are self describing.<p>Additionally, when using asymmetric validation, you can rely on JWTs as licenses: Your software can restrict offline features based on a locally stored token, simply by checking that the JWT was signed by the authority. In tandem with the ability to store metadata, your app (with code held by the untrusted user) can use the token to determine the user&#x27;s license features without requiring an always on connection. (Obviously patching out the license checks is another matter)<p>These features can be layered on top of opaque tokens, but since a JWT has all the benefits of an opaque token (store the opaque token as a claim just like the rest of the metadata), it&#x27;s actually a complete package that does it all without needing to roll it yourself.
评论 #40504276 未加载
gizzlon12 months ago
You <i>can</i> implement a blocklist of all the revoked JWT and publish it to all servers. The list should be small, because only otherwise valid tokens need to be included. It becomes so much more complicated than a simple check-the-db setup though.<p>I don&#x27;t think I would start with JWT if I did this again.
评论 #40492607 未加载
评论 #40504410 未加载
评论 #40492164 未加载
firefoxd12 months ago
Some people made the distinction here, jwt on the front end vs the micro services across the network.<p>I&#x27;ve experienced more than once, issues where the auth service has bugs and the logged out session is still valid for a long time. Or an attacker that figured out the micro services blueprint and now had authed access to the entire network.<p>Jwt is still useful between services, however the front end can do just fine with a session id that can be easily revoked.
redwoolf12 months ago
I keep reading criticism of JWTs that involves impersonation or replay attacks. With JWT (or non JWT bearer tokens) you use a refresh token. It seems to me that if an attacker gets a JWT they also have the refresh token. So how are JWTs inherently more insecure than other authentication methods? Almost all data passed over the wire nowadays is TLS encrypted.<p>In my projects, we have used encrypted JWTs and it seems to me a fine solution. Log out can be implemented in a user facing client by deleting the JWT and refresh token. Given a short enough expiration time, this is sufficient for most use cases involving user facing applications. Isn’t it? Generally, at least in the domains of the applications I’ve worked on, users only intend to log out of their current application when logging out. Meaning if they are signed in on their phone and on their desktop browser, when they sign out in the browser they don’t intend to also log out of their phone application.<p>The only downside I see is that if you want to log out of all sessions it is impossible to implement without maintaining session state in the server.
评论 #40504381 未加载
评论 #40497024 未加载
4star3star12 months ago
I&#x27;m unconvinced of the author&#x27;s actual understanding of common JWT usage.<p>Suppose you use Azure. You may have one or more app registrations with defined roles as well as apis exposed within the Azure config. It&#x27;s convenient to acquire an access token that can be sent to various apis, each of which can accept the token without having to worry about session state or really anything to do with authentication other than validating the token&#x27;s legitimacy. If I wanted to roll my own security, maybe JWT isn&#x27;t how I would choose to do it, but I definitely don&#x27;t want to do that.
nu11ptr12 months ago
The article is just as wrong as articles that say you should use JWTs. They are both wrong because they lack context, at least in their opening. Interestingly, the article eventually does give context, but saying &quot;it depends on what you need to do&quot; apparently doesn&#x27;t get as many clicks as starting by saying &quot;no&quot;.<p>For the record, I use JWTs, I have hardly any scale at all. I have none of the requirements that would hit the database on each request. It works just fine and I didn&#x27;t need to consult an article to tell me what to think because, and this is the crazy part I know, I&#x27;m able to break apart my business requirements and decide for myself what is needed (or not). JWTs work just fine in my case. YMMV.
meling12 months ago
A former student of mine (Vera Yaseneva) redesigned our old auth architecture using jwts and I’m pretty happy with how it turned out. Maybe it is overkill for our simple autograder server, but it was fun getting it to work and I’m sure it is more secure than the old architecture which had many many flaws… it was a maintenance nightmare for years. After the redesign it has been a breeze. Here is the project <a href="https:&#x2F;&#x2F;github.com&#x2F;quickfeed&#x2F;quickfeed">https:&#x2F;&#x2F;github.com&#x2F;quickfeed&#x2F;quickfeed</a><p>The security arch is mainly in web&#x2F;auth and web&#x2F;interceptor packages if anyone is interested in learning from the code. It uses connectrpc, which has a nice interceptor arch.<p>Happy to share Vera’s thesis report if anyone is interested…
评论 #40493673 未加载
shermantanktop12 months ago
So what’s “Facebook scale”? Is there an edge TPS number? Number of discrete major services? If you are consistently doing 10TPS on 3 services, sure. But many systems are bigger than that.<p>Everyone wants to be big. You can either frontload those problems, and risk drowning in irrelevant complexity, or defer them. The problem with deferring is that switching lanes appears like it will be expensive and time consuming.<p>The secret is that if you solve actual problems, rather than dreams and future hopes, the answers are almost always obvious. The work may be painful and people may be angry, but the rationale will be clear.
lvlabguy12 months ago
You should not use JWT if you have a single application in your organization. However, whenever you have multiple applications, you need some form of central authentication &#x2F; authorization service. Otherwise, you would have to maintain auth databases in each application, each application will need to be logged-in separately, you won&#x27;t be able to implement a simple &quot;suspend a user&#x27;s accounts after X unsuccessful auth attempt&quot;, you won&#x27;t have a central auth log.
conradludgate12 months ago
A big problem not addressed when not using a signature based authorization scheme is that you need to hit your database for every access attempt. This makes you much more susceptible to ddos attacks.<p>You need to be able to turn away malicious users as fast as possible. If you take the time to check a database first, that&#x27;s a precious resource they can consume.<p>&quot;Add a cache!&quot;, you might say? What if they use random client id and client secret for every request, how do you cache against that?
评论 #40492441 未加载
评论 #40492418 未加载
评论 #40492547 未加载
评论 #40492755 未加载
rblatz12 months ago
Oh man, he goes straight to stateful services as an alternative to JWTs. What an absolute nightmare, if JWTs are too hard stateful services are certainly more difficult.
评论 #40492735 未加载
评论 #40495460 未加载
thayne12 months ago
So first of all, JWT is part of the OpenID Connect specification. So if you want to be either a service provider or identity provider for OIDC, you need to use JWTs as an authentication token in at least some cases.<p>Secondly, you don&#x27;t have to hit the database on every request. Unless you have really strict security requirements, you can have a short expiration time on the jwt with a refresh mechanism, and then you only have to check the database say once every 5 minutes.<p>Related to the above point, the database you check for the &quot;session&quot; token isn&#x27;t necessarily the same as the one used for other data used in the request, even if you are much smaller than Google or Facebook. It might not even ve the same type of database.<p>Finally, even if it makes sense to use a &quot;traditional&quot; session cookie for brower sessions, that probably doesn&#x27;t make sense for an external API, where the client may not have persistent cookies at all, and there may not really be a concept of a session.<p>So as was mentioned in another comment, I think the answer to the title question is a solid &quot;it depends&quot;.
therealfiona12 months ago
Here I was hoping someone was using the James Webb Telescope to do some crazy authentication process that I never could have imagined. Was hoping something like the Cloudflare lava lamp wall, but much slower.
mstaoru12 months ago
JWTs are rather convenient for API access, especially for APIs that are hit at high req&#x2F;s rate, as they allow to decouple auth check and actual request processing. In more complicated cases you can use JWT subject for some simple preflight ACL checks as well.
rendall12 months ago
While I could agree with the sentiment &quot;consider using opaque auth tokens instead of JWTs in most use cases&quot; I can&#x27;t get behind the opinion-presented-as-factual-statement tone of the article. There are valid use cases to offload authentication to the client rather than verifying an opaque token with every request. One advantage is that community support for JWTs is large, but home-grown, ad-hoc opaque token solutions not so much. Another is that any claim at all can be stored in the JWT: IP address, user name, opaque token, whatever makes your app secure. While these same claims <i>could</i> be stored in a database, now you have extra overhead and maintenance dealing with them.<p>I would like to see an open-source project from this author that uses his proposed solution.
评论 #40494967 未加载
评论 #40495932 未加载
phendrenad212 months ago
I&#x27;m thankful every day I don&#x27;t have to work on a team where JWTs are a valid solution, and nobody suggests them regardless. What a nightmare.
alex_young12 months ago
“No.”<p>Whenever I see such a simple answer to a complex question, I know it’s probably an oversimplification.<p>The real answer is a solid “it depends on what you want to achieve.”<p>Say you handle invalidation by maintaining a cached table of revoked tokens. Is this table larger or smaller than the table of all users?<p>Perhaps you would like to embed some RBAC info in the token. Is validating both the token and it’s absence from your revocation table more efficient than looking up all of the other information?<p>Perhaps you need to do this on a distributed basis. Is the overhead of maintaining such a table more or less than making all the DB calls and creating a central choke point in your architecture?
Aldipower12 months ago
Fair enough, access token&#x2F;refresh token pairs all have those issues described in the article. But why hating against JWTs (pronounced &#x27;JOT&#x27; btw) in general? There are other stateless techniques making use of a JWT, which are very easy and secure to implement. For examples the single auth token approach, with maybe a 2 days expiry and a renew window if the user is active. For some scenarios this is perfectly fine, it is stateless and has no refresh token. User logs out by just deleting the token client side.
评论 #40493839 未加载
weinzierl12 months ago
Using JWT from Keycloak just to obtain a session cookie. Is this a common pattern or a smell?
评论 #40492226 未加载
评论 #40493745 未加载
tzahifadida12 months ago
Probably a waste of time to answer due to the long thread here. But short answer: you can store tokens in a server session which will manage it for you. In case you need to refresh it, you are redirected to the idp and get a refreshed token which again stored inside the session. So you can handle any &quot;microservice&quot; scenario as was called here, not sure why micro is important... Also, it is a misconseption that the tokens,as it where, are not stored on the oidc providing service. How are you going to logout someone or invalidate or simply track devices? It is going to be stored somewhere and there is nothing wrong with it. It is matter of scale, if you are not facebook the addition is miniscule, especially with distributed cache. Again, a misconseption it is not being used already, e.g. on keycloak if you want HA you have to enable distributed cache. So really naive thinking that session is bad or jwt is bad. They are simply tools used by protocols and the only question is usually what do you prefer unless you get to the edge cases of performance which unless you are facebook, my face would look daughtful to begin with if you raise this argument.
评论 #40494028 未加载
stanac12 months ago
1. You can set JWT as cookie value, I think author is describing OAuth 2 problems, not JWT problems. Interestingly JWT is not mentioned in OAuth 2 spec [0].<p>2. JWT doesn&#x27;t have to contain user details, it can be a simple reference token used for introspection [1]. This approach removes problems with invalidation and logout since identity service should store invalidated tokens.<p>3. JWT can contain refresh token id (or hash) and check for invalidated refresh tokens in (distributed) cache. Cache entry should not be long lived, and refresh token shouldn&#x27;t be long lived if you are using proper refresh token rotation with family invalidation in case of a leak.<p>That being said cookies are still simplest and safest bet for simple monolith applications.<p>[0] <a href="https:&#x2F;&#x2F;datatracker.ietf.org&#x2F;doc&#x2F;html&#x2F;rfc6749" rel="nofollow">https:&#x2F;&#x2F;datatracker.ietf.org&#x2F;doc&#x2F;html&#x2F;rfc6749</a><p>[1] <a href="https:&#x2F;&#x2F;datatracker.ietf.org&#x2F;doc&#x2F;html&#x2F;rfc7662" rel="nofollow">https:&#x2F;&#x2F;datatracker.ietf.org&#x2F;doc&#x2F;html&#x2F;rfc7662</a>
ChicagoDave12 months ago
The JWT has some extra fluff for the client, but only the Bearer token is used for secure communication. And every call to an API validates the Bearer token with an identity service. There is no automatic security because you have a token. That Bearer token (not the JWT) must clearly be validated and also validated with whatever functionality (Claims) is potentially being requested.<p>The meta data in the JWT is sort of a short cut to let the front-end make assumptions, but it has no bearing on the actual capabilities. Only a valid Bearer token can determine if a call is secure (authenticated) and has the correct permissions (authorized).<p>So, you don&#x27;t need a JWT, but without it, you&#x27;re still going to need a way to send mundane meta data back to the front-end. This used to be (and still can be) a separate call for &quot;config&quot; or &quot;permissions&quot; data, but why bother. Just create claims in your identity server, mark your API&#x27;s with those claims and token validation, and you&#x27;re in great shape.
评论 #40499620 未加载
skywhopper12 months ago
This article has a pretty narrow view of what uses a JWT can be put to. Yeah, in his limited examples, JWT is overengineered. And for non-distributed systems, JWT is overengineered. But there are plenty of use cases where JWT can simplify things and minimize complexity. Eg, when network connectivity is restricted and the consuming service cannot talk to the issuing service. Or when using a single token to auth against multiple remote systems. Or when latency is high between the central auth system and the consuming service. Or when you don’t have tight TTL&#x2F;revocation concerns and you just want to auth once a day or week. Or when you just need a one-time token to establish some other service relationship. Or when you want to scope down permissions to subsets of what’s possible, or embed arbitrary auth metadata into the token, JWT has solutions for you.<p>But if you just think of this author’s narrow view of what system designs look like, then skip the JWT.
cryptonector12 months ago
This is a bit nonsensical. Using the same logic regarding logout&#x2F;revocation you would also be opposed to using Kerberos, say. So let&#x27;s discuss the whole logout&#x2F;revocation case.<p>In a typical Windows&#x2F;AD or Unix installation you might have Kerberos (definitely in the Windows&#x2F;AD case, possibly in the Unix case) <i>and</i> a directory (definitely in both cases, though in the Unix case it might be purely local), and you use the authentication system (Kerberos, say) in such a way that it allows you to elide some directory lookups on Windows&#x2F;AD or not at all on Unix. Either way you get a worst-case latency for revocation of the user&#x27;s service ticket&#x27;s lifetime (Windows) or whatever you do to stop locked user processes (Unix). Well, that&#x27;s the theory, but in practice many SSHv2&#x2F;whatever implementations do not force session end at ticket expiration. So Windows&#x2F;AD uses group policy for revocation. On the Unix side... we don&#x27;t really have a standard solution, but essentially one can build a daemon that periodically looks for and kills processes running as now-locked users.<p>(For SSHv2, if you build re-authentication into a KEX, like GSS-KEX does, then you can force re-authentication and session end when authentication expires. In practice on Unix systems it&#x27;s not really possible to elide a directory, so this is not necessary.)<p>Now for HTTPS apps it&#x27;s a different story. You can use cookie expiration and force re-authentication so that revocation latency is bearer token lifetime, then keep bearer token lifetimes short. If you don&#x27;t control the token issuer then you can still impose a shorter cookie lifetime in your app and demand a fresh token when you force re-authentication.<p>In any case, one does not need a revoked token&#x2F;ticket&#x2F;whatever list!<p>But it <i>is</i> true that bearer tokens don&#x27;t completely elide the need for a directory for things like SSH logins onto hosts. But they do for HTTPS apps.<p>So I think TFA is just wrong.
abalone12 months ago
I see a flaw in the argument. He shifted from saying you&#x27;d use a 5 minute access token timeout to querying the DB on every request. There can actually be a big difference between those two scenarios. Some web APIs can be bursty. Even caching credentials for 5 minutes could take significant load off the DB.
评论 #40496696 未加载
1penny42cents12 months ago
It’s a great analysis but I think it’s too either-or.<p>If you have a monolith anyways then yes, why use a distributed systems solution like JWT? Completely agree.<p>But if you already have an auth service, making it optional for the majority of requests is a distributed systems win. Even if you need to implement forced logout or some other features which require hitting the auth database, they can be optional requests. If the auth service is available, you get better security, otherwise the services can decide whether to continue or not.<p>This is better than your entire app going down or slowing down with the auth service. Though the refresh token bit is still a challenge, it’s a smaller one than a hard dependency on the auth service on every request.<p>Again, if your auth service is just a component in your monolith, the author is completely right. It’s context-specific.
bakugo12 months ago
The beauty of JWTs is that, if you have to ask &quot;do I need JWTs?&quot;, you probably don&#x27;t need JWTs.
dudeinjapan12 months ago
At TableCheck we use JWTs to enable user logins across several sub-apps, using an auth service we built in-house using Elixir.<p>It’s a well-documented standard and we’ve never had an issue with them since launching.<p>The supposed drawback that sessions must live for X minutes, is just not a problem in practice.
评论 #40497521 未加载
nine_k12 months ago
Yes. I mean, no; you should use macaroons [1] instead, which are better than JWTs but are built on similar ideas.<p>[1]: <a href="https:&#x2F;&#x2F;fly.io&#x2F;blog&#x2F;macaroons-escalated-quickly&#x2F;">https:&#x2F;&#x2F;fly.io&#x2F;blog&#x2F;macaroons-escalated-quickly&#x2F;</a>
egberts112 months ago
Wrote a brief recap of &quot;permission&quot; and &quot;login&quot; for authentication from my work in JavaScript malwares.<p>It was a rush outline article with citations.<p>Large binning, salting of hash, and revocatable are my criteria.<p>Some toolkits that went out the window firstly are:<p>* auth0,<p>* Fusion auth, and<p>* Gluu.<p>So, some of the basic criteria are:<p>* User and password login instead of plain HTTP session cookies.<p>* HTTP-only over TLS v1.2+ (secured HTTP, HTTPS)<p>* ECDSA 1K or better<p>* SameSite [1]<p>* __Host prefix [1]<p>* preload HTTP Strict-Transport-Security header line [2]<p>* Bearer token supplied by API clients<p>* Don’t listen on port 80… like ever. Or revoke token if over non-port 443.<p>* DO NOT use JWT [3]<p>* DO NOT use CORS [4]<p>Hope the citations help more.<p>JWT, not recommended, IMHO.<p><a href="https:&#x2F;&#x2F;egbert.net&#x2F;blog&#x2F;articles&#x2F;authentication-for-api.html" rel="nofollow">https:&#x2F;&#x2F;egbert.net&#x2F;blog&#x2F;articles&#x2F;authentication-for-api.html</a>
评论 #40496133 未加载
grepLeigh12 months ago
JWT make the most sense for zero trust machine to machine authentication, where you might also want to authorize certain verbs&#x2F;actions&#x2F;roles after confirming the requester&#x27;s identity. For example, I use a JWT-based authentication and role-based authorization scheme for a fleet of Raspberry Pis communicating with each other on a LAN or network overlay, and also with a multi-tenant API on a public internet-facing VM. The Pis manage 3D print jobs.<p>For users&#x2F;people&#x2F;apps, I usually rely on session-based authentication. Sometimes I need light RBAC at this layer too (users, teams, admins, etc).
DeathArrow12 months ago
I don&#x27;t get why he is pretty sure everybody has only one database which stores user data and application data. At work we have user data in Keycloack and application data in at least 20 different databases.
vldb712 months ago
I don’t think it is either-or type of choice. A lot, if not all arguments against that use of JWT disappear if you’re ok with compromise solution: user management actions will take time to propagate. If JWT lifetime is 5 mins, it means that all actions like logout, deactivating account etc will take 5 mins to finalize - and you’d be hitting the database exactly once per 5 mins for the purpose of checking if user is still active, refresh token is not barred by log out etc.
Galanwe12 months ago
The article misses the point of JWT: it&#x27;s dead simple to implement.<p>I don&#x27;t implement JWT because I fancy big data terascale technologies. I do it because it&#x27;s mostly stateless, meaning it&#x27;s very easy to mock locally, and easy to deploy.<p>&gt; You wanted to implement log-out, so now you’re keeping an allowlist of valid JWTs, or a denylist of revoked JWTs. To check this you hit the database on each request.<p>No, you just remove the JWT from the local storage. Sure, the user could then relogin if he copied it, but if it&#x27;s on his own will, why not. And if he got his JWT stolen before logout, bah anyway any token could have been stolen that way, whatever the tech.<p>&gt; You need to be able to block users entirely, so you check a “user active” flag in the database. You hit the database on each request.<p>Right but that contradicts the whole premise of the article, being that you probably don&#x27;t need fancy features. 99.9% of websites don&#x27;t need to ban users _instantly_. If you have a fair JWT expiration, it&#x27;s usually OK.<p>I&#x27;d argue for the exact opposite of the article. If you want dead simple Auth, without fancy tech, just use JWT.
评论 #40492842 未加载
评论 #40493011 未加载
评论 #40492748 未加载
jmartrican12 months ago
I worked in a backend team that introduced JWT, before I got there. The problem we had with JWT was that the data was stale. Even if it wasn&#x27;t stale, it needed to be treated as stale because every service wanted the up to date data, even within 1 sec that data is old. The user could have changed something in their account from the time that the JWT was issued. I removed JWT and went back to the old UUIDs as tokens.
YetAnotherNick12 months ago
&gt; In this setup the refresh token, not the authentication token, is the real session token<p>Yes, and why is that a problem? It is the best of both worlds as the verification of access token is standardized and fast while refresh token could be used at the first call of the session. Yes, it could happen that the user is logged in for 5 more minutes if the user is in middle of session, but it&#x27;s really such a edge case which most companies don&#x27;t need to worry about.
Joel_Mckay12 months ago
In general, a breadcrumb or cookie with symmetrically encrypted session UUID, epoch time, IP, and transaction counter is wise. You should also permute the servers hash salt with date daily to boot session campers.<p>If for some unknown reason the recovered client transaction counter losses its expected position, than you know someone has tampered with the session, and or stolen your clients session token.<p>Donate to the FOSS project of your choice if you find this useful. =3
menthe12 months ago
Everyone’s talking about how you MUST hit the database for revocations &#x2F; invalidations, and how it may defeat the purpose.<p>How is no one thinking of a mere pub-sub topic? Set the TTL on the topic to whatever your max JWT TTL is, make your applications subscribe to the beginning of the topic upon startup, problem solved.<p>You need to load up the certificates from configuration to verify the signatures anyways, it doesn’t cost any more to load up a Kafka consumer writing to a tiny map.
评论 #40494099 未加载
评论 #40493528 未加载
评论 #40493188 未加载
jankboy12 months ago
Yes if the JWT token can only become invalid based on an expiration time. You can add the expiration time in the token and check it during authentication.<p>No if the token can become invalid due to other reasons because lets say the user deletes the token because it got leaked. But since you have no way of invalidating the token other than changing the encryption key, you can&#x27;t selectively invalidate that one token.
fennecbutt12 months ago
I personally love jwts. It&#x27;s been suggested in other comments that you can just store tokens in a dB or something.<p>Why would I, I can just issue a jwt and move on, I don&#x27;t need to store anything apart from a key to check it with.<p>And using jwts with nodejs (which I use most frequently) is a super simple and easy npm install, it&#x27;s almost zero effort to use a jwt.
devdiary12 months ago
Start with usual session based authentication. Keep it until you see the absolute need to move to JWT. And make sure you understand JWT and &quot;invalidating JWT&quot; before using it - <a href="https:&#x2F;&#x2F;github.com&#x2F;gitcommitshow&#x2F;auth-jwt?tab=readme-ov-file#invalidating-jwt">https:&#x2F;&#x2F;github.com&#x2F;gitcommitshow&#x2F;auth-jwt?tab=readme-ov-file...</a>
jonplackett12 months ago
I’d like to hear a reply from someone at Supabase
koliber12 months ago
Nothing wrong with JWT bearer tokens as a technology.<p>However, too many times they&#x27;re implemented incorrectly or without forethought. I&#x27;ve seen a few teams who used the bearer token, set the age really high, and never bothered to implement a refresh mechanism.<p>Fast forward a few months and someone says it is not possible to log someone out of our service.
benced12 months ago
I like the idea of using JWTs as opaque tokens. It sets you up nicely to migrate to using them semantically and there&#x27;s very little downside (you just need a JWT library where the tokens are minted and then it&#x27;s just string equality everywhere else) if you never actually end up using JWTs.
axelv12 months ago
What about jwt&#x27;s in a session cookie? I think the whole story needs more nuance. JWT&#x27;s have many purposes.
winternewt12 months ago
Without JWT, how do you support log in using third party identity providers like Office 365, Google or Facebook?
blntechie12 months ago
I have used OAuth2 with and without JWTs as bearer tokens and pretty much used them the same way. JWT helps with fetching the user details without having to hit the DB&#x2F;backend, and that&#x27;s basically was the only difference to me.<p>I believe the issues he is describing is more OAuth2 rather than JWT.
ahasani12 months ago
While mignt not agreeing with all the reasons mentioned, verifying signature for every resource access is cpu intensive (your commercial compute provider would love you though). Comparing session id to a map is cheap. For me jwt to authenticate and random session token for resource access, problem solved
greenthrow12 months ago
This post is not very good. JWTs exist for good reasons. They may not fit your needs, and if not, don&#x27;t use them. But they exist to allow Entity A to tell Entities B through Z that A had authenticated the user and authorizes them without needing to make API calls, and they serve that purpose well.
PaulHoule12 months ago
Here is a quote from a comment in that article:<p><pre><code> I feel like this subject comes up every couple of months with another iteration of why people think JWTs are bad. </code></pre> The regularity which with this subject comes up makes me think of how Triplebyte used to pay off bloggers in the day to write posts with the title “hiring is broken”. I don’t have the proof but I am picking up a bad smell here.<p>Gotta be <i>yet another</i> of the vendors which is selling some authentication system that they host. I remember trying to promote an open source user management system in the early 2000s and nobody cared until they added killer feature “our service will get shut down when we get acquired” which somehow drew the pointy haired boss like a moth to a flame.
tobystic12 months ago
Isn’t JWT plaintext? Just remember your security controls<p><a href="https:&#x2F;&#x2F;owasp.org&#x2F;www-chapter-vancouver&#x2F;assets&#x2F;presentations&#x2F;2020-01_Attacking_and_Securing_JWT.pdf" rel="nofollow">https:&#x2F;&#x2F;owasp.org&#x2F;www-chapter-vancouver&#x2F;assets&#x2F;presentations...</a>
评论 #40495490 未加载
Savageman12 months ago
Maybe it&#x27;s irrelevant but for JWT to be passed as a Bearer in the header Authentication header, it needs to be accessible from the browser? Aren&#x27;t httpOnly cookie safer in this regard? Or do we see set the JWT in the cookie too?
评论 #40496041 未加载
datarez12 months ago
The main advantage of jwt is that is stateless, so it reduces load on database and or caching layer when checking user session. Alongside being able to share the public key to verify the token across different services
jongjong12 months ago
JWT is the simplest and most versatile authentication mechanism we have.<p>I have no idea why there is so much gaslighting about them. People keep pointing to implementation complexity, yet there exist proven, heavily used implementations for almost every language and engine imaginable. That issue is an issue of the past.<p>It is doubly ironic that people try to point to &#x27;complexity&#x27; as an argument against them when most of them are addicted to over-engineered software stacks... JWTs are amazingly simple when compared to most other concepts in this industry.<p>The aversion towards JWT is weird. I used to think it&#x27;s probably because some people got burned badly due to past implementation flaws and still hold a grudge... But the sheer persistence of the any-JWT movement leads me to think there may be an agenda behind it.<p>How could anyone possibly claim that keeping track of sessions on the back end and passing around session IDs is superior? It&#x27;s way more expensive on the database&#x2F;datastore, adds latency, it&#x27;s hard to scale, you often end up with stale sessions because it&#x27;s not fail-safe (e.g. how to clean up previously active sessions when a worker crashes? Especially if you have multiple workers.). Session IDs are MUCH more work.
评论 #40503966 未加载
crunchybeeftaco12 months ago
I’m confused though. JWT isn’t hard to configure. Why not just use it?
评论 #40497163 未加载
pan6912 months ago
My take on it is;<p>JWTs are good for server to server communication (short lived at ~5 minutes).<p>Sessions are for clients (browsers, apps, anything controlled by a person) to communicate with a server&#x2F;api.
dwhitney12 months ago
oof - this article is pushing bad advice - general disclaimer: use a third party authentication system like Okta or Cognito. It&#x27;s going to save you so much grief down the road. They pretty much all use the same pattern (OIDC), so you just need to learn it once, and you&#x27;re good for at least another decade. Authentication is one of the easiest and most important things to take off of your plate. Do it.
osigurdson12 months ago
What if you want to use AzureAD or Auth0? Aren&#x27;t those services completely built around jwts?
评论 #40495512 未加载
begueradj12 months ago
The article completely ignores single page applications where these JWT can be needed a lot.
dathinab12 months ago
It&#x27;s the wrong question.<p>It&#x27;s like asking what language should I use for programming a game? A common question, but of which the answer isn&#x27;t a language choice. Instead it is that you approach the problem from the wrong direction.<p>The more useful question is what framework&#x2F;service&#x2F;library do I use for handling that, and then you use whatever it uses. Which most times means use whatever your web framework provides (as the blog author concluded).<p>The next question is what do you concretely hope to get from doing so and are there easier ways to get it (likely yes, and not some vague &quot;but statles is better argument&quot;).<p>Then ask yourself how do you handle revocation? A question which is essential when using JWT and other stateless auth tokens (a answer of idk.&#x2F;I will think later about don&#x27;t count. I don&#x27;t can be a valid answer, but only very very rarely).<p>I think it&#x27;s not an understatement to say that the huge majority of custom JWT usage falls under harmful premature optimization.<p>I wrote &quot;custom&quot; because sometimes you don&#x27;t have a choice, e.g. you need to use OIDC for social login as the main form of AuthN &amp; AuthZ and then already have some service (not just library) which fully handles OIDC&#x2F;JWT including revocation for you (i.e. you don&#x27;t validate the JWT stateless but ask the service every time). Through that approach (especially the later part) can have scaling limits but, eh, we are back at premature optimization ;)
adeptima12 months ago
JWT is not a protocol but kind of a message format from my perspective.<p><a href="https:&#x2F;&#x2F;www.rfc-editor.org&#x2F;rfc&#x2F;rfc7519" rel="nofollow">https:&#x2F;&#x2F;www.rfc-editor.org&#x2F;rfc&#x2F;rfc7519</a><p>It can be signed with HMAC SHA-256 algorithm: {&quot;typ&quot;:&quot;JWT&quot;, &quot;alg&quot;:&quot;HS256&quot;}<p>Ripping off JWT from surrounding context is a road to hell.<p>It&#x27;s worth to study JWT in context of OIDC (OpenID Connect) IDP providers.<p>You will quickly bump into buzzwords like client (RP), server (OP), PKCE, Token Exchange, mTLS and all kind of Implicit. Hybrid flows.<p>My biggest regret I didn&#x27;t go through JWT related RFCs and OpenID Connect specs earlier.<p>[1]: <a href="https:&#x2F;&#x2F;openid.net&#x2F;specs&#x2F;openid-connect-core-1_0.html#CodeFlowAuth" rel="nofollow">https:&#x2F;&#x2F;openid.net&#x2F;specs&#x2F;openid-connect-core-1_0.html#CodeFl...</a> 3.1. Authentication using the Authorization Code Flow<p>[2]: <a href="https:&#x2F;&#x2F;openid.net&#x2F;specs&#x2F;openid-connect-core-1_0.html#ImplicitFlowAuth" rel="nofollow">https:&#x2F;&#x2F;openid.net&#x2F;specs&#x2F;openid-connect-core-1_0.html#Implic...</a> 3.2. Authentication using the Implicit Flow<p>[3]: <a href="https:&#x2F;&#x2F;openid.net&#x2F;specs&#x2F;openid-connect-core-1_0.html#HybridFlowAuth" rel="nofollow">https:&#x2F;&#x2F;openid.net&#x2F;specs&#x2F;openid-connect-core-1_0.html#Hybrid...</a> 3.3. Authentication using the Hybrid Flow<p>[4]: <a href="https:&#x2F;&#x2F;openid.net&#x2F;specs&#x2F;openid-connect-core-1_0.html#ClientAuthentication" rel="nofollow">https:&#x2F;&#x2F;openid.net&#x2F;specs&#x2F;openid-connect-core-1_0.html#Client...</a> 9. Client Authentication<p>[5]: <a href="https:&#x2F;&#x2F;openid.net&#x2F;specs&#x2F;openid-connect-core-1_0.html#RefreshTokens" rel="nofollow">https:&#x2F;&#x2F;openid.net&#x2F;specs&#x2F;openid-connect-core-1_0.html#Refres...</a> 12. Using Refresh Tokens<p>[6]: <a href="https:&#x2F;&#x2F;openid.net&#x2F;specs&#x2F;openid-connect-discovery-1_0.html" rel="nofollow">https:&#x2F;&#x2F;openid.net&#x2F;specs&#x2F;openid-connect-discovery-1_0.html</a> OpenID Connect Discovery 1.0 incorporating errata set 1<p>[7]: <a href="https:&#x2F;&#x2F;www.rfc-editor.org&#x2F;rfc&#x2F;rfc7523.html" rel="nofollow">https:&#x2F;&#x2F;www.rfc-editor.org&#x2F;rfc&#x2F;rfc7523.html</a> JSON Web Token (JWT) Profile for OAuth 2.0 Client Authentication and Authorization Grants<p>[8]: <a href="https:&#x2F;&#x2F;www.rfc-editor.org&#x2F;rfc&#x2F;rfc7636.html" rel="nofollow">https:&#x2F;&#x2F;www.rfc-editor.org&#x2F;rfc&#x2F;rfc7636.html</a> Proof Key for Code Exchange by OAuth Public Clients<p>[9]: <a href="https:&#x2F;&#x2F;www.rfc-editor.org&#x2F;rfc&#x2F;rfc8693.html" rel="nofollow">https:&#x2F;&#x2F;www.rfc-editor.org&#x2F;rfc&#x2F;rfc8693.html</a> OAuth 2.0 Token Exchange<p>[10]: <a href="https:&#x2F;&#x2F;www.rfc-editor.org&#x2F;rfc&#x2F;rfc8628.html" rel="nofollow">https:&#x2F;&#x2F;www.rfc-editor.org&#x2F;rfc&#x2F;rfc8628.html</a> OAuth 2.0 Device Authorization Grant<p>[11]: <a href="https:&#x2F;&#x2F;www.rfc-editor.org&#x2F;rfc&#x2F;rfc8705.html" rel="nofollow">https:&#x2F;&#x2F;www.rfc-editor.org&#x2F;rfc&#x2F;rfc8705.html</a> OAuth 2.0 Mutual-TLS Client Authentication and Certificate-Bound Access Tokens&quot;<p>If you dont have patience for RFCs and specs, just go play with open sources IDP or better start from OpenID Connect client and server library, and try to integrate it into your &quot;hellohell&quot; app ;)<p>Very soon you will find out why developers keep building their own IDPs and how simple OpenID Connect can become a full time business<p>Go back here and here <a href="http:&#x2F;&#x2F;cryto.net&#x2F;~joepie91&#x2F;blog&#x2F;2016&#x2F;06&#x2F;19&#x2F;stop-using-jwt-for-sessions-part-2-why-your-solution-doesnt-work&#x2F;" rel="nofollow">http:&#x2F;&#x2F;cryto.net&#x2F;~joepie91&#x2F;blog&#x2F;2016&#x2F;06&#x2F;19&#x2F;stop-using-jwt-fo...</a><p>And reflect yourself<p>Trust nobody
zie12 months ago
Not to mention it&#x27;s ridiculously easy to make JWT&#x27;s insecure.
评论 #40492316 未加载
评论 #40492102 未加载
评论 #40492590 未加载
snowstormsun12 months ago
One huge benefit of random session tokens is also that you can&#x27;t include arbitrary metadata that is sent to the client.<p>Decoding JWTs of web apps can give you a lot of suprises like the account email address or even password being stored inside them. For devs that don&#x27;t know the difference between signing and encrypting JWTs are a footgun and even for those that do it can be confusing. The specifications are also a hard read. A handful of RFCs where you don&#x27;t really know which one to lookup. JWT, JWK, JWE, JWA, WTF? It seems to do everything at once, signing and encryption, symmetric and asymmetric, and the format is always quite similar!<p>On the other side, if you are able to avoid the many pitfalls, JWTs can be very useful in the right place when used properly. You could probably write an equally or more secure JSON based token format from scratch without that much effort by just keeping it simple and restrictive&#x2F;opinionated, though.
评论 #40494464 未加载
ramesh3112 months ago
So then why does Auth0 use JWTs for everything..?
评论 #40492157 未加载
评论 #40492188 未加载
评论 #40492218 未加载
评论 #40492310 未加载
评论 #40493034 未加载
hansoolo12 months ago
Off topic: the domain name is great!
drivebycomment12 months ago
The main claim of the article is:<p>&gt; jwt as authentication tokens are constructed for Google&#x2F;Facebook scale environments, and absolutely no one who is not Google&#x2F;Facebook needs to put up with the ensuing tradeoffs.<p>The first sentence is factually incorrect. Google doesn&#x27;t use JWT for most of its own authentication. Try analyzing their traffic - web and mobile apps - and you&#x27;ll find that none of their 1st party applications &#x2F; web use JWT. They do use JWT for OIDC, for third parties, which makes sense since with OIDC&#x2F;JWT, third party sites can verify the token without talking to Google using a standard. This is largely similar for Facebook.<p>JWT RFC starts with:<p>&gt; JSON Web Token (JWT) is a compact, URL-safe means of representing claims to be transferred between two parties.<p>Notice &quot;between two parties&quot;. Of course, nothing stops from a single party to use JWT, but claiming JWT was invented for &quot;Google&#x2F;Facebook scale environments&quot; implying they are using it for their 1st party authentication is just factually wrong. JWT was always meant to be an information transport between two separate parties, like OIDC.<p>&quot;Ensuing tradeoffs&quot; here is essentially about stateless authentication vs stateful authentication, and even there, this &quot;absolutely no one&quot; is simply incorrect. There are many scenarios where stateless authentication is sufficient, even for the authentication for a single party (let alone between two separate parties). Not all applications and use cases require the security properties of stateful authentication - a sufficiently short expiration would provide sufficient security in many cases, making the loss of any security worth it for the added benefit of simplicity and reliability with the stateless authentication.<p>Now with more nitpick:<p>The article claims, since &quot;denylist&quot; would require a database read, it&#x27;s equivalent to stateful authentication. Theoretically that&#x27;s true. In practice, denylist has some nice properties, that makes it worthwhile if server-side logout is the only missing feature you need from JWT. Denylist is often very small - if most users of your application or service do not explicitly log out, the number of denylist will remain very small. With the expiration, the size can not grow indefinitely either. Thus, the denylist you maintain can be much smaller than the record of all stateful authentication - which makes it cheaper&#x2F;easier to replicate &#x2F; cache across your systems than the full authentication records. So &quot;denylist&quot; is definitely a legitimate design option, with slightly different trade-offs than a full stateful authentication.<p>---<p>If I re-interpret the main claim of the article in the way I think would make sense, it would be: services should prefer stateful authentication, and the cost of stateful authentication is lower than people imagine it to be. That I can be behind 100%. As written, the article is at best some big exaggeration with incorrect details and hidden assumptions.
endisneigh12 months ago
Jwts are fine, just use them properly.
评论 #40492090 未加载
评论 #40492405 未加载
5cott012 months ago
fine with me as long as you don&#x27;t pronounce it &quot;jay double-u tee&quot;
评论 #40492841 未加载
flexterra12 months ago
no
jongjong12 months ago
&gt; Now, let’s assume you are not Google. Check which of these apply to you:<p>&gt; You wanted to implement log-out, so now you’re keeping an allowlist of valid JWTs, or a denylist of revoked JWTs. To check this you hit the database on each request.<p>A JWT is like a keycard. If a hotel gives you a keycard to access your room, the card itself holds the credentials which give you access to the room. That&#x27;s the core principle behind JWT.<p>If you want to ban someone due to malicious conduct, then you need some kind of ban mechanism but this is a concern of spam prevention and attack mitigation. You need such mechanism regardless of what session mechanism you use. With JWT, you may need to do 1 lookup to check the account object (you can keep an isBanned flag on the account itself), with regular session IDs, you need 2 lookups (1 for the account object and 1 for the session object). JWT still saves you 1 lookup... Also, if gives you a lot of flexibility. For example, you may be able to keep a &#x27;blacklist&#x27; in-memory and separate for each worker (that may be appropriate for certain use cases); you&#x27;re not necessarily forced to hit a datastore or database as claimed. Banning and spam prevention should be seen as a separate concern.<p>Also, at small scale, there are scenarios where you don&#x27;t even need a blacklist. Maybe your app is being served on an internal private network or maybe it&#x27;s public but it&#x27;s not so critical that you can&#x27;t wait for 10 minutes or 1 hour (or whatever) for the JWT to expire for the ban to take effect. I mean, with the physical hotel scenario as an example; your keycard remains active until it expires. There are many such scenarios in the software industry where a ban doesn&#x27;t need to take effect immediately.<p>When you need instant blocking for DDoS protection (where immediacy of the ban&#x2F;block really matters), you typically rely on IPs, not specific account or session IDs.<p>&gt; You need to be able to block users entirely, so you check a “user active” flag in the database. You hit the database on each request.<p>As above.<p>&gt; You need additional relationships between the user object and other objects in the database. You hit the database on each request.<p>The number of times you hit the database (and the reason for each lookup) matters and it&#x27;s important not to mix up different concerns.<p>&gt; Your service does anything at all with data in the database. You hit the database on each request.<p>This is just a variation which has the same flaws as previous arguments.<p>The author claims that Session IDs provide:<p>&gt; Greatly reduced complexity. No need to manage a secure jwt signing&#x2F;authentication key<p>You can provide the auth key as an environment variable when you launch the service. This is well supported in all environments at any scale including Docker, Kubernetes... anyway, 99% of services rely on various secrets like API keys so you need to pass secrets as env vars anyway, what&#x27;s the issue with having just one more env var to hold the JWT signing auth key? There is no added complexity there as the mechanism for handling such secrets already exists in most applications. It&#x27;s rare to see an application which doesn&#x27;t have secret API keys... You need them for payments (e.g. Stripe API), for database API services (e.g. MongoDB cloud), Amazon AWS, etc...<p>On the other hand, managing sessions on the back end requires weird workarounds like setting and constantly refreshing expiries on the session keys or running complex cleanup cron jobs because you end up with complicated situations where your worker might crash and leave behind stale sessions. Session IDs are much more complicated.<p>Not to mention that session lookups becomes a single point of failure and can become a bottleneck for your application as you get more users. It&#x27;s really difficult to scale well. You&#x27;re going to run a Redis cluster just to manage sessions? Hello LATENCY!!! Welcome DDoS headache!!! Did anyone say backpressure issues??? How are you going to clean up stale sessions when a worker crashes? Good luck.<p>I hope you&#x27;re billing for your development work by the hour, coz you&#x27;re gonna need a lot of those! I hope your health insurer covers Panadol! Don&#x27;t be surprised when GlaxoSmithKline opens up a new factory next to your office.
评论 #40504025 未加载