8 ms·
Ten years of JSON Web Token and preparing for the future
- 90s_dev 1y ago> It’s often said that one sign of a standard having succeeded is that it’s used for things that the inventors never imagined. It's certainly a sign of something's utility and versatility, for sure. Congrats.
- vrosas 1y agoIf you go back and search hacker news for any article involving JWTs or OAuth you’ll find hundreds of comments of circular arguments over what a JWT is and is not. People never seem to be able to separate the two.
- 90s_dev 1y agoI still don't really understand them. The last time I used them was for a client probably in 2016 or 2018, and I forgot everything I learned about them. But they have an RFC so that's pretty cool.
- marifjeren 1y agoI think an easy way to think about them is it's just a json object, with some cryptographic crud glued to it that proves who created it.
- deeringc 1y agoJSON Web Tokens are part of the JSON Object Signing and Encryption (JOSE) family of standards which are really just containers for cryptographic primitives in a web-friendly representation. Most people are aware of JWS (signed payloads) but there are also JWE (encrypted payloads) and JWK (key payloads). If you're building any sort of cryptographic system that needs to represent encrypted/signed values or keys, you can use JOSE to represent these primitives without having to reinvent the wheel. By far the biggest use of JOSE is in authentication systems where JWS are used as signed bearer tokens but that's just one application and there are many others. They arent perfect, but they filled an important gap when they were created and made it much easier to deal with crypto at an application layer compared with all of hte binary formats that are used in things like TLS.
- saffsffefewafew 1y ago[dead]
- nibman 1y ago[dead]
- genghisjahn 1y agoI love JWTs between servers. Between servers and clients, you just end up remaking cookies/sessions. Strictly my experience/opinion. Glad to hear from others.
- slt2021 1y agoyou cant generally reuse cookies across domains, because browser controls which domain receive which cookie. Also cookies are not cryptographically signed and thus easily forgeable by the client/browser. JWTs on the other hand allow to be used across domain, so that you can use JWT issued by your IDP on one domain, to be trusted on another domain. crypto signature helps in verifying integrity of data. sessions are usually tied to a single backend/application server. Its hard to reuse a session data across different apps. JWTs on the other hand allow sharing session data across different app servers/microservices.
- gerdesj 1y ago"Also cookies are not cryptographically signed and thus easily forgeable by the client/browser." My Apache webby thingies quite happily dole out encrypted cookies: https://httpd.apache.org/docs/2.4/mod/mod_session_crypto.html https://httpd.apache.org/docs/2.4/mod/mod_session_crypto.htm... Your notes on cross site issues are also described there. JWTs are mutually shared secret passable with nobs on - you can store loads of data in them. Cookies are more one shot and one piece of data.
- formerly_proven 1y agoEncryption generally doesn’t provide authentication, so I wouldn’t be surprised if that Apache module allows a user to flip is_admin=0 to 1 because the encryption is sufficiently malleable to do that. Especially because that page mentions 3DES.
- kevlened 1y ago> Also cookies are not cryptographically signed and thus easily forgeable by the client/browser While it's true that you could avoid signing cookies, this isn't the default for any server library I'm aware of. If your library doesn't require a secret to use for signing, you should report it. I'm also unaware of JWT libraries that default to "none" for the algorithm (some go against the spec and avoid it entirely), though it's possible to use JWTs insecurely.
- deleted 1y ago[deleted]
- methou 1y agoJWTs are just too fat, and JS users often forgets encoding is not encryption. I've seen some news site trackers send JWT in url/header to some 3rd party tracker. Content is no surprise, my full name, and email address, violates its own privacy policy. Otherwise it's very open and handy, from inspecting a jwt token I can learn a lot about the architectural design of many sites.
- jpc0 1y ago> Content is no surprise, my full name, and email address Not sure if I’m remembering correctly but isn’t it recommended to not store any identifiable information in a JWT precisely because of this?
- littlecranky67 1y agoWell JWTs are signed - signing is not encryption per se. But there are also JWE which are mentioned in the linked article. They are fully encrypted.
- unscaled 1y agotptacek's survey was already mentioned here, but I think it should be more famous. https://fly.io/blog/api-tokens-a-tedious-survey https://fly.io/blog/api-tokens-a-tedious-survey Unfortunately, it seems like 99% of the industry decides which token to use based on Medium articles, LLM responses or how many unmaintained packages that implement this thing they can find on NPM. JWT is mostly used as an access token, but for the vast majority of use cases it's a bad fit. If you've got low traffic no strict multi-region deployment requirements, random IDs are the best approach for you. They are extremely lean and easy to revoke. It's pretty secure: the only common vulnerabilities I can think of with this approach are session fixation[1] and timing attacks[2]. Both attacks are preventable if you take just a few simple precautions: 1. Always generate 32-byte session IDs using a cryptographically secure random number generator on authentication. (Never re-use existing session IDs for new logins) 2. Either use a cryptographic hash (e.g. SHA-256 or Blake2b) of the session ID a the database field used when querying sessions or make sure that the Session ID field is indexed with a hash-based index (B-trees are susceptible to timing attacks). In cases where you really cannot use Session IDs, your service is usually big enough and important enough to use custom Protobuf tokens even a more special-purpose format like Macaroons. These formats give can be far more compact and give you full control on designing for your needs. For instance, if you want flexible claims (with most of them standardized across your services), together with encryption, you can use a combination of Protobuf and a libsodium secret box envelope. [1] https://owasp.org/www-community/attacks/Session_fixation https://owasp.org/www-community/attacks/Session_fixation [2] e.g. https://github.com/advisories/GHSA-cvw2-xj8r-mjf7 https://github.com/advisories/GHSA-cvw2-xj8r-mjf7
- marifjeren 1y agoLove JWTs but I wish there was a better standard for conveying detailed and compact authorization information, for systems requiring enforcement of complex authorization rules. We experimented once with trying to put permissions on a JWT (more complex than your popular scopes) but that makes them grow quickly. And we experimented with putting role information on JWTs but that results in re-centralization of logic. Maybe conveying complex authorization info via a single object that gets passed around repeatedly is fundamentally a flawed idea, but if I had an identity standards wishlist that would be near the top.
- Bilal_io 1y agoOh yeah the token grows in length very quickly, we also tried using it 5 years ago to pass in roles to the client and ended up with many issues
- cyberax 1y agoAuthorization is really not a generally solvable problem. Every large system ends up having its quirks. Attempting to generalize it ends up in pain, suffering, and AWS IAM.
- khana 1y ago[dead]
- JimDabell 1y agoYou might want to check out Biscuit: > Biscuit is an authorization token with decentralized verification, offline attenuation and strong security policy enforcement based on a logic language — https://www.biscuitsec.org https://www.biscuitsec.org
- kgeist 1y ago>We experimented once with trying to put permissions on a JWT (more complex than your popular scopes) but that makes them grow quickly. We solved it by simply using bitmasks. Say, you want to encode an access rule "allows reading from Calendar objects". The typical CRUD actions can be encoded with 4 bits. For example, all bits are zero => no access. The first bit is 1 => can create. The second bit is 1 => can read. Etc. Then, say, if your system has 32 different types of objects, you can say that, "position 13 encodes for calendars". So you get 32*4 = 128 bits, i.e. just 16 bytes to encode information about CRUD rules for 32 different types of objects. Sure it sounds complicated but if you move it to a library, you stop thinking about it.
- pelagicAustral 1y agoJWTs are a vanity project of the JS community... I am still waiting for a use case that cannot be served by traditional key exchange...
- mdaniel 1y agoDid you mean cert exchange, because keys are just a very long password, but certs carry actual information about the holder (err, I guess pedantically of the holder with the key)
- some_furry 1y ago> Did you mean cert exchange, because keys are just a very long password My experience differs: My private key is only 256 bits (32 bytes, which base64 encodes up to 44 characters, if you use padding). My typical passwords are 40-64 characters (unless stupid requirements force me to go shorter).
- Uvix 1y agoWhat algorithm are you using? RSA keys are normally at least 2048 bits in length.
- magicalhippo 1y agoI'd put money on Ed25519[1][2]. [1]: https://en.wikipedia.org/wiki/EdDSA#Ed25519 https://en.wikipedia.org/wiki/EdDSA#Ed25519 [2]: https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms https://www.iana.org/assignments/jose/jose.xhtml#web-signatu...
- some_furry 1y agoWhy would I use RSA when Ed25519 is right there?
- firesteelrain 1y ago> JWTs are a vanity project of the JS community JWTs are standardized (RFC 7519) and used outside the JS ecosystem. Not a vanity project Though often overused and poorly misunderstood where simpler and more secure methods would suffice.
- hdjrudni 1y agoEvery time I want to use a JWT, it seems like it's the suboptimal choice, so I've never found a genuine use case for them. Most recently, I wanted to implement 2FA w/ TOTP. I figure I'll use 1 cookie for the session, and another cookie as a TOTP bypass. If the user doesn't have a 2FA bypass cookie, then they have to complete the 2FA challenge. Great, so user submits username & password like normal, if they pass but don't have the bypass cookie the server sends back a JWT with 10 minute expiry. They have to send back the JWT along with OTP to complete the login. I figure this is OK, but not optimal. Worst case, hacker does not submit any username/password but attempts to forge the JWT along with OTP. User ID is in clear text in the JWT, but the key only exists on the server so it's very difficult to crack. Nevertheless, clients have unlimited attempts because JWT is stateless and they can keep extending the expiry or set it to far future as desired. Still, 256 bits, not likely they'll ever succeed, but I should probably be alerted to what's going on. Alternative? Create a 2FA challenge key that's unique after every successful username/password combo. User submits challenge key along with OTP. Same 256 bit security, but unique for each login attempt instead of using global HMAC key. Also, now it's very easy to limit attempts to ~3 and I have a record of any such hacking attempt. Seems strictly better. Storage is not really a concern because worse case I can still prune all keys older than 10 minutes. Downside I guess is I still have to hit my DB, but it's a very efficient query and I can always move to a key-value store if it becomes a bottleneck. I don't know, what's the use-case? Server-server interaction? Then they still need to share a key to validate the JWT. And probably all but the user-facing server doesn't need to be exposed to public internet anyway so why the hoopla adding JWT? I haven't looked into it much because I don't believe in this microservice architecture either, but if I were to go down that road I'd probably try gRPC/protobufs and still not bother with JWT.
- gerdesj 1y agoA JWT can include claims - that's the difference: JWTs are a bit more complicated data structure out of the box. You can do authN and authZ in one go. You can do it all via individual browser cookies but it will be complicated. However you can dump session cookies to a database and then you can do claims locally on the server and use that cookie to tie it all together. So I think you can do it either way. JWTs are mutually authenticated (shared secret) but cookies are not.
- nssnsjsjsjs 1y agoIs there an RSS feed for this blog?
- JimDabell 1y agoYes, it’s linked using the standard autodiscovery rel=alternate meta element. You should be able to just paste the site URL into whichever feed reader you use to subscribe.
- francislavoie 1y agoPaseto is better https://paseto.io/ https://paseto.io/, but unfortunately OAuth forces the usage of JWT.
- cyberax 1y agoI fail to see how it's better, except for hand-waving about potential crypto attacks? It seems to be a NIH-ed serialization format with hard-coded ciphersuits. It doesn't seem to support use-cases like delegation and claims.
- francislavoie 1y agoWatch the talk at the bottom of the page. JWT/JOSE are chock full of dangerous footguns that aren't just theoretical, they have repeatedly been shown to be poorly designed and too risky to implement correctly as written. Using fewer, known secure cryptographic primitives as part of the spec ensures it's impossible to get the security wrong, can't be misused.
- cyberax 1y agoI am not going to watch the talk. The slides from it are unavailable either. And sorry, but the article https://paragonie.com/blog/2017/03/jwt-json-web-tokens-is-bad-standard-that-everyone-should-avoid https://paragonie.com/blog/2017/03/jwt-json-web-tokens-is-ba... is just weak. The only real vulnerability is the key type confusion (HS256 vs. RSA256) enabled by libraries in weakly-typed languages, and easily fixed. Other: > RSA with PKCS #1v1.5 padding is vulnerable to a type of chosen-ciphertext attack, called a padding oracle. Not applicable. > If you attempt to avoid invalid curve attacks by using one of the elliptic curves for security, you're no longer JWT standards-compliant. This is just nonsense. JWT allows Ed25519: https://www.rfc-editor.org/rfc/rfc8037 https://www.rfc-editor.org/rfc/rfc8037 Moreover, I'm not aware of real attacks against NIST curves.
- francislavoie 1y agoThe point is that the JWT spec leaves it open to the implementer which primitives to use, which invites bad implementations to be insecure. PASETO requires a small subset of known secure primitives, preventing that problem altogether. It's not "just nonsense". Here's a list of "alg: none" JWT vulns. Every one of these would've been avoided had the standard been something like PASETO which didn't allow that. https://github.com/zofrex/howmanydayssinceajwtalgnonevuln/blob/deploy/data/vulns.yml https://github.com/zofrex/howmanydayssinceajwtalgnonevuln/bl... You say "I am not going to watch the talk" and then you continue to argue in bad faith. Please walk away if you're not going to engage honestly.
- jrvarela56 1y agoPre-req from HN lore: https://fly.io/blog/api-tokens-a-tedious-survey/ https://fly.io/blog/api-tokens-a-tedious-survey/
- martinald 1y agoThe problem I've got with JWTs is that actually you can rarely (never, really in my experience?) assume anything in the JWT apart from user id are valid for a long period of time. For the most simple use case of an client auth state; you want to be able to revoke auth straight away if an account is compromised. This means you have to check the auth database for every request anyway, and you probably could have got whatever else was in the claim there quickly. Same with roles; if you downgrade an admin user to a lower 'class' of user then you don't want it to take minutes to take effect. So then all you are left with is a unified client id format, which is somewhat useful, but not really the 'promise' of JWTs (I feel?).
- paulddraper 1y agoI think you have a narrow view. For example, a magic link sent via email can have a substantial validity duration.
- ithkuil 1y agoYes but generally magic links are only used for authentication. So if you delete or downgrade the principal whoever uses that magic link to authenticate can only perform the operations that are associated to the principal and the check is performed after the magic link is verified, unless the magic link also used to carry auth claims
- paulddraper 1y agoYes, up-to-date permissions require centralized consistency. My point is…JWT can be used in a number of contexts.
- lo0dot0 1y agoClicking on links in emails is a security risk because they could be spam. I don't do that unless it's the only way to move forward and then I double check the url. Basically I only use it to sign up then never again if possible.
- hn_throwaway_99 1y ago
- TheChaplain 1y agoI don't really get the point of JWT these days with SameSite and CSP-headers available. And from the backend perspective, most frameworks have session tracking built-in with cookies so it's super easy to dismiss one or all clients. With JWT however, that rarely exist and you need to re-implement the whole session-shebang in order to keep track of the clients.
- littlecranky67 1y agoSamesite/CSP Headers and JWT are orthogonal to each other. I use a JWT system for authenticating my SPA against the REST backend, but store the JWT in a cookie (using SameSite=strict and HttpOnly).
- unit149 1y ago[dead]
- pawanjswal 1y agoJWT has really shaped the modern web!
- pjmlp 1y ago10 years of tooling pain, more likely. I don't know what the better solution looks like, but dealing with OAuth and JWT setups is kind of horrible, regardless of the technology stack being used.
- rvz 1y agoOne of the worst standards ever made.
- grxar 1y agoI would like to hear your opinion about how to invalidate a token, the 2 options we have so far: 1 query the db on every request and 2 cache for some minutes the db data, seems both don't fit well in a modern web development
- littlecranky67 1y agoTradeoff: You can't implement individual token revocation, but you can easily implement a "Logout on all devices" system. You have a timestamp with a "minimum issued at" attached to each identity, and if that identity (user) choses to "logout from all devices", you set the timestamp to the current time. Upon validating a token you only make sure the issued-at (iat) is after your "minimum issued at". I think it is a real good trade-off, as in case of a security breach you have an easy way to mitigate leaked tokens. The downside is, your user will have to re-login all devices. If you do not want to burden your users with the login on all devices, you should ask your self how often you do have security breaches and leaked tokens, might be you have others issues going on.
- santiagobasulto 1y agoI think the rule of thumb should be to ALWAYS start with Cookies for client/server authentication, with all the security features enabled by default. HttpOnly, Secure and SameSite. Then, if that has some sort of limitation for your app's specific use case, you can see to migrate to JWT. But the standards are standards for a reason.
- flsaflkelfe 1y ago[dead]
- sachahjkl 1y agoJSON Computer
- mooreds 1y agoHere's an interesting video from an identity conference a few years ago. The speaker is Brian Campbell who was one of the JWT spec authors. https://www.youtube.com/watch?v=IgKRGS6cQWw https://www.youtube.com/watch?v=IgKRGS6cQWw Here's the video description: > JWT is an IETF standard security token format that, due to perceived simplicity and widespread library availability, has been extremely popular in recent years. Despite that popularity (or maybe, in part, because of it), JWT has been heavily derided by reputable people in information security ("horrible standard", "RFC was made by monkeys", "Internet’s worst cryptography standard", "JWT is a disaster ... amazing how bad it is", "simplistic, complicated, and unsafe all at the same time", and "almost impossible to build a secure JWT library" ...give just a taste of the sentiment). > The criticism has been substantiated and amplified by a steady stream of public vulnerabilities in libraries and deployments. Indeed there have been serious and legitimate security problems with JWT and many of them can be attributed directly to fundamental flaws in the specification itself that allowed, or even encouraged, such implementation mistakes. But is JWT irredeemably flawed? This session will endeavor to take a hard look at that very question (complete with the presenter's own sense of inadequacy and fear of culpability in JWT's flaws) with a review/overview of JWT fundamentals and a pragmatic look at each of the most common and/or biting criticisms and associated real-world vulnerabilities.
- tsarchitect 1y agoDabvid Blevins has a great video (2018) that mentions JWTs https://www.youtube.com/watch?v=osQmFNm0YDU https://www.youtube.com/watch?v=osQmFNm0YDU He discusses the architectural advantages of JWT but also discusses JWTs lacking "JWTs are a passport without a picture. A very dangerous thing". His solution: OAuth2 + JWT + Signatures
- tzahifadida 1y agoOne thing that I dont like about jwts is that all rest calls must include that huge thing. A simple old school sessionid as a cookie is smaller and will pass the request faster. You can store the session in the database or redis or cache in memory, really who really have millions of users? Why go for the most complicated setup?
- sroussey 1y agoThe meat of the article is to point to this link: https://www.ietf.org/archive/id/draft-sheffer-oauth-rfc8725bis-01.html https://www.ietf.org/archive/id/draft-sheffer-oauth-rfc8725b... JSON Web Token Best Current Practices