5 ms·
I like seeing the "you're struggling toward reinventing JWT; consider just using JWT" discussion play out in the comments. (Spoiler: the dev ends up deciding to
by throwanem 9y ago
I like seeing the "you're struggling toward reinventing JWT; consider just using JWT" discussion play out in the comments. (Spoiler: the dev ends up deciding to just use JWT.)
- jchw 9y agoJWT is a great idea, but in practice the actual specification is broken in dumb ways. You may as well lob off the entire header portion of the token since there's no sense in listening to what it says.
- throwanem 9y agoSure, but if I'm not actually setting out to reinvent auth, I'm still better off going with a suboptimal but basically functional standard like JWT than I am trying to roll my own.
- jchw 9y agoIf you would've used this logic just a little while ago and slapped an off-the-shelf JWT library into your app, you'd have a trivially exploitable design flaw that could be used to easily forge tokens. In that case, reinventing the wheel properly probably would've been more secure, if not perfect. I personally use JWT, but unfortunately like so many other things you can't just drop it in and forget; you have to have some level of care if you really want it to work. All cryptography has its caveats. OTOH, going with simple, server-issued tokens that don't carry data actually is pretty proven already, so it's not really that bad of an idea anyways, if you are only ever going to have a few servers in the same region anyways.
- StavrosK 9y agoYeah, JWT, like YAML, was one of those dead-simple, great ideas that ended up overcomplicated and error-prone.
- throwanem 9y agoAll else equal, I'm more likely to find out about a dumb gotcha in a commonly used standard before it bites me than I am in my own sui generis design that nobody else uses. You're right that crypto of any sort requires care in how we use it, but preferring a more widely used method lets us leverage the care of others as well as our own. And if we don't bother, we're probably about as hosed either way. And, yeah, if it's practical to just generate and issue a secret from the server side and authenticate it at a single point when the client presents it back to us, we may as well do that. I'm not sure how practicable an option that is in OP's case, though; the description of the problem suggests there's something rather strange going on, and I don't grasp it well enough to speak to what scheme is really most useful in the context. But it does sound like having the client bear its own claims is useful, and JWT would be the obvious go-to for the use case.
- tptacek 9y agoWhat terrible standard could you ever avoid given this logic? I could just as easily convince you to use raw XML DSIG with this argument; after all, in the dichotomy you propose, your only alternative would be a DIY reimplementation of XML DSIG. Why not find a way to fit IKE into your design as well? What, are you going to redesign your own IKE?
- throwanem 9y agoOf course this argument is rather useless when taken as the sole metric by which to decide whether and which standards to use, or implementations to prefer. But why would anyone do such a nonsensical thing as that?
- davewritescode 9y agoThere’s so much FUD around JWT that I feel compelled to answer this everytime it comes up. Just to get it out of the way, you’re correct that the JWT spec doesn’t do a lot to prevent implementors from doing stupid things, particularly bad was downgrade attacks from asymmetric to symmetric keys. Here’s the thing, these issues don’t exist anymore. Amazon’s Cognito relies heavily on JWT and I tend to trust Amazon’s security folks.
- jchw 9y agoThis is not FUD. It is a design flaw. It is now widely recognized that the header component of the JWT token cannot be used except to reject a token, making it pretty close to absolutely useless (except for debugging.) HOWEVER. Before this was recognized, most JWT implementations were broken and were easily susceptible to the most basic of downgrade attacks. Downgrading from asymmetric to symmetric was a slap in the face for obvious reasons, but that's just the last round of problems. The early problems were even more ridiculous; many libraries would readily downgrade to 'none' and turn off protection altogether. Not just Amazon Cognito, but Google's OIDC implementation, and indeed, all OIDC implementations, use JWT. JWT implementations today are hopefully no longer susceptible to basic lapses in security. But there's good reason for its reputation: the way it's designed lead to these trivial downgrade attacks. Having the token specify the algorithm was a bad decision, and it lead to bad implementations. Importantly, someone implementing JWT today could easily make some of the same mistakes if they aren't careful. I hope a future JWT release entirely removes the information from the token and just forces the client/server to agree statically.
- tptacek 9y agoI agree strongly that JWT is badly flawed, and that criticisms of JWT don't constitute "FUD". JWT's uptake has been alarming given how little cryptographic engineering input the format seems to have received, versus how complex it is under the hood. That said: Asymmetric crypto is a crypto code smell. You use it when you absolutely have to because there's no other way to express what you're trying to accomplish. It is much harder to get public key crypto right than it is to safely use a "Seal/Unseal" AEAD interface. One of the things that alarms me about JWT is that it's a format that presumes developers might want to effortlessly switch between symmetric and asymmetric crypto, as if they were just two different ways of solving the same underlying problem.
- unscaled 9y agoI find it hard to recommend JWT unless you're already a security expert. This is unfortunate, since JWT was meant to bring client-side tokens to the masses, but the reality is that: 1. JWT has amazing cross-language support, but most of the libraries out there are unaudited, and even the ones that are audited can change and, let's say, make the 'None' signer the default one: https://github.com/lcobucci/jwt/commit/6507ac39be5a5e06457c8ff8ad2c4d51d7d7b998 https://github.com/lcobucci/jwt/commit/6507ac39be5a5e06457c8... 2. JWT can be used somewhat responsibly, but the JWT spec does n't enforce any security measure and doesn't even contain proper recommendations like: a. Never use the None algorithm. b. Never use the RSA algorithm. c. Basically, only use HMAC (or Ed25519 if supported). d. Always include an issue timestamp ('iat' claim) and possibly a unique nonce ('tid') to make tokens unique. e. Always do key rotation using 'kid'. f. Implement a blacklist-based token revocation mechanism (or use short-lived access tokens backed by DB-based refresh tokens). g. Include the token expiry claim! Seriously, JWT doesn't even require token expiry! h. Don't use JWE. h. Associate your keys with signature algorithms, and _make sure that token is signed with the right alorithm_: https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/ https://auth0.com/blog/critical-vulnerabilities-in-json-web-... 3. I'm yet to encounter a library which enforces good defaults on your JWT usage. Some libraries validate expiry by default (if the claim exists), but from my experience most of them don't set it by default. Almost no library contains an convenience method for setting the issue time or a nonce, let alone setting them by default. 4. No JWT library I know of provides help for implementing basic features like key rotation/revocation and token revocation. Without these features JWT security model becomes vastly inferior to database-backed tokens. The reality is that developers implementing JWT choose it exactly because they don't want to delve into all these complications of using tokens, so they just pick up a library and hack something around it, expecting the JWT library to take care of all the security issues for them.
- caseysoftware 9y agoIt is broken but at the same time, if you don't send the header, you're not using a real JWT according to RFC 7519. If you're going to use JWTs - even with all their flaws - please use them properly.
- tptacek 9y agoWhat's treacherous about JWT is that the programming interface is extremely simple and pretty closely approaches the ideal of what developers would want from secure clientside storage. It's a great interface, but terrible crypto. https://news.ycombinator.com/item?id=14292223 https://news.ycombinator.com/item?id=14292223
- throwanem 9y agoYou're right! You need a strong engineering culture around its use to avoid its pitfalls, and without that, the results are often regrettable. And I agree, too, that this is a failing of the standard, not of those who use it. But it's also true that JWT has legitimate use cases; I'm working with it right now in my professional capacity, and we are using it precisely because "twenty bytes of hexified /dev/urandom" isn't a terribly efficient option at our scale - we could do it, but we won't, because it doesn't add value to the business. As you say, though, the crypto sucks. You know a great deal, both in the absolute and relative to my own knowledge, about such things. What, in your estimation, is the means most likely to produce an outcome where we have something of roughly similar utility and ease of use, but with solid crypto and few or no bear traps for the unwary engineer? (Beyond just removing the algorithm negotiation, or at least the "none" option.) Or does such a thing exist and I'm just one of today's lucky 10,000?
- tptacek 9y agoRails applications have been doing stateless auth in encrypted cookies for over a decade, and the constructions they use to do it are safer than JWT's, and orders of magnitude less complex. I would want to push back on the idea that a good use case for JWT is "we need to do stateless auth". Stateless auth is a bad place to start. But, when you need it, there are better ways to do it than JWT.
- unscaled 9y agoYou can start with running your JSON data (or whatever serialization format that you choose) through NaCl/libsodium's crypto_secretbox() and you already get more than what JWT offers by default. It still doesn't include everything you need of course: at the very least you'll still need to implement expiry validation and some token revocation mechanism. But you actually get more value out of the box than you get with a JWT library: your token content is encrypted, your using a solid crypto library and you don't have to mess around with any knob to secure your implementation. It doesn't offer support for hot-swapping crypto algorithms, but for what it's worth, cryptographic agility is the root cause of many issues we had with TLS in the past[1]. If you end up needing both symmetric and asymmetric cryptography in your tokens, you better treat them as two different types of tokens, because they usually are. I think tptacek already said, but asymmetric crypto is rarely interchangeable with symmetric crypto - you usually use them in very different cases. [1] https://www.imperialviolet.org/2016/05/16/agility.html https://www.imperialviolet.org/2016/05/16/agility.html