1. 40

  2. 40

    Reprising and reformatting something I wrote on that other site about this:

    The problem with JWT/JOSE is that it’s too complicated for what it does. It’s a meta-standard capturing basically all of cryptography which wasn’t written by or with cryptographers. Crypto vulnerabilities usually occur in the joinery of a protocol. JWT was written to maximize the amount of joinery.

    Negotiation: Good modern crypto constructions don’t do complicated negotiation or algorithm selection. Look at Trevor Perrin’s Noise protocol, which is the transport for Signal. Noise is instantiated statically with specific algorithms. If you’re talking to a Chapoly Noise implementation, you cannot with a header convince it to switch to AES-GCM, let alone “alg:none”. The ability to negotiate different ciphers dynamically is an own-goal. The ability to negotiate to no crypto, or (almost worse) to inferior crypto, is disqualifying.

    Defaults: A good security protocol has good defaults. But JWT doesn’t even get non-replayability right; it’s implicit, and there’s more than one way to do it.

    Inband Signaling: Application data is mixed with metadata (any attribute not in the JOSE header is in the same namespace as the application’s data). Anything that can possibly go wrong, JWT wants to make sure will go wrong.

    Complexity: It’s 2017 and they still managed to drag all of X.509 into the thing, and they indirect through URLs. Some day some serverside library will implement JWK URL indirection, and we’ll have managed to reconstitute an old inexplicably bad XML attack.

    Needless Public Key: For that matter, something crypto people understand that I don’t think the JWT people do: public key crypto isn’t better than symmetric key crypto. It’s certainly not a good default: if you don’t absolutely need public key constructions, you shouldn’t use them. They’re multiplicatively more complex and dangerous than symmetric key constructions. But just in this thread someone pointed out a library — auth0’s — that apparently defaults to public key JWT. That’s because JWT practically begs you to find an excuse to use public key crypto.

    These words occur in a JWT tutorial (I think, but am not sure, it’s auth0’s):

    “For this reason encrypted JWTs are sometimes nested: an encrypted JWT serves as the container for a signed JWT. This way you get the benefits of both.”

    There are implementations that default to compressing plaintext before encrypting.

    There’s a reason crypto people table flip instead of writing detailed critiques of this protocol. It’s a bad protocol. You look at this and think, for what? To avoid the effort of encrypting a JSON blob with libsodium and base64ing the output? Burn it with fire.

    1. 3

      I have a related but somewhat OT question. In one of the articles linked to by the article [1], they say this:

      32 bytes of entropy from /dev/urandom hashed with sha256 is sufficient for generating session identifiers.

      What purpose does the hash serve here besides transforming the original random number into a different random number? Surely the only reason to use hashing in session ID generation is if there’s no good RNG available in which case one might do something like hash(IP, username, user_agent, server_secret) to generate a unique token? (And in the presence of server-side session storage there’d be no point to including the secret in the hash because its presence in the session table would prove its validity.)

      [1] https://paragonie.com/blog/2015/04/fast-track-safe-and-secure-php-sessions

      1. 2

        Yeah, if urandom is actually good, then hashing it serves no real purpose. (In fact if you want to get mathematical, it can only decrease the randomness, but luckily by an absolutely negligible amount). Certain kinds of less-than-great randomness can be improved by hashing (as a form of whitening), but no good urandom deserves to be treated that way.

        1. 2

          The reason for that is PHP is weird. PHP hashes session entropy with MD5 by default. Setting it to SHA256 just minimizes the entropy reduction by this step. There is no “don’t hash, just use urandom” configuration directive possible (unless you’re rolling your own session management code, in which case, please just use random_bytes()).

          This is no longer the case in PHP 7.1.0, but that blog post is nearly two years old.

        2. 2

          Thanks for that very thorough dissection of JWT. Are there web app frameworks/stacks that do have helpfully secure and well-engineered defaults that you’d recommend?

          1. 1

            The post itself offers a suggestion (at the bottom): use libsodium.

            1. 1

              The author refers to Fernet as a JWT alternative. https://github.com/fernet/spec/blob/master/Spec.md

              However, Fernet is not nearly as comprehensive as JOSE and does not appear to be a suitable alternative.

              1. 2

                Hah, it seems the article changed a few times, and not just the title…

          2. 7

            This is a fine post, but I’m surprised how much more attention it got than the totally ignored post about the invalid curve attack (which I would guess inspired this post). “We want in depth technical articles. No, no, not that technical. Too deep, too deep, pull up.”

            1. 4

              You mean this one? If so, I bet the word “adobe” made a lot of people not click it.

              1. 4

                yeah, which is a shame.

              2. 1

                Yeah, not only was that that was far more innovative research than anything I’ve blogged about to date, it was one of the inspirations for this post.

                As an attempt to mitigate this, I’m going to update my post to emphasize that attack and get more eyes on theirs. It’s good work.

              3. 6

                JWT != JOSE.

                For reference:

                JOSE RFC

                Other RFC’s

                EDIT: Looks like the authors are aware. They just changed the title from “JWT (JSON Web Tokens) is a Bad Standard That Everyone Should Avoid” to “JOSE (Javascript Object Signing and Encryption) is a Bad Standard That Everyone Should Avoid”

                1. 5

                  Do you know what all these “You Are Bad because you don’t understand Crypto” rants remind me of?

                  The early days of Numeric Methods.

                  Endless rants about you using the wrong technique for ….

                  And then the “Numerical Recipes in *” juggernaut rolled by and flattened all the whinges.

                  We really need a “Cryptographic Recipes in *” series of books.

                  1. 6

                    So, to be clear: you should not use them for sessions. They are fine for claims and tokens. Just don’t ignore the part where you verify that a request is signed.