News for hackers. Stuff that matters.
Re:Things to Use Instead of JSON Web Tokens by Freak_NL on Monday May 08, 2017 @05:42AM (#14290298)
> The problem with JWT is the user gets to choose which algorithm to use.

Only if you completely bungle the implementation on the server-side. The 'none' 'algorithm' isn't supported by up-to-date JWT libraries with a good track record, and you should always limit the algorithms you'll allow on the server. So if you sign your tokens with a RSA-2048 key-pair, you would discard any token that isn't using that algorithm.

Of course if you are building an API that blindly accepts whatever it receives from a user agent you are bound to create a security gap — but that holds true for anything users send you though, not just JWTs. JSON Web Token is not that hard to grok, and it isn't a 'foot-gun' technology (just practice trigger discipline — i.e., read the documentation).

I'm a Java guy, so I'll limit my experience to the libraries available there, but of the four Java libraries available, three provide strict validation of the signing algorithm out of the box, and explicitly document this in their examples and documentation (I think the fourth does too, but I haven't tried that one myself).

JSON Web Token is a neat standard that has a lot of good parts that can reliably be used to create and process authentication tokens. So if you are still worried about developers getting it wrong, then instead of saying 'don't use JWT', why not promote a safe subset of the specification instead and promote that? Call it 'iron-jwt' or something. It beats rolling your own solution.

Or if you want to be particularly constructive and feel that developers are misusing this technology, write a sensible, short, to the point implementers guide for using JWT and spread the word.

Re:Things to Use Instead of JSON Web Tokens by JimDabell on Monday May 08, 2017 @07:17AM (#14290665)
> Only if you completely bungle the implementation on the server-side.

Which happens with regularity. This is exactly what led to the vulnerabilities mentioned in the article.

This is a bit like arguing against the claim that generating SQL queries by concatenating strings is unsafe. "Only if you completely bungle escaping the parameters", right? As it turns out, that's an extremely common mistake. It's easier to use a known-safe practice like parameterised queries than it is to rely on developers avoiding this pitfall each and every time they have to execute an SQL query.

Likewise with this. We know that negotiating the algorithm is subject to mistakes, and it offers no benefits. So instead of relying on developers avoiding this pitfall each time, let's avoid the pitfall altogether and get rid of negotiation.

There's a human aspect to security that's being missed here. Saying what boils down to "well developers shouldn't write insecure code" doesn't actually stop developers from writing insecure code. You can point the finger after the fact, but if you want to actually improve security, we need better standards than this.

Re:Things to Use Instead of JSON Web Tokens by Freak_NL on Monday May 08, 2017 @07:33AM (#14290723)
> This is a bit like arguing against the claim that generating SQL queries by concatenating strings is unsafe. "Only if you completely bungle escaping the parameters", right?

No, you document how it should be done. Any major database layer using SQL provides parametrised SQL queries, and strongly suggests developers use that (usually in the quick start guide). You can still do your own concatenation, but aren't advised to.

The JWT libraries that are up-to-date and well-documented don't recommend blindly trusting the algorithm set in the header either, they recommend safe approaches such as configuring your whitelist and letting any unlisted algorithms fail. For example:

https://github.com/auth0/java-jwt#verify-a-token

Only if you completely refuse to read even the basic 'getting started' documentation will you get to this kind of weird vulnerability. The issues with this part of the JWT standard have been addressed by the libraries, what remains is just a little bit of effort on the part of the developer — which may be expected from someone writing security critical code.

That is, don't blame the hammer for the shoddy carpentry.

> So instead of relying on developers avoiding this pitfall each time, let's avoid the pitfall altogether and get rid of negotiation.

So write a concise pamphlet that can easily be shared with all of the JWT libraries in an issue/bug report. If there is a good argument for having to explicitly whitelist algorithms, they might welcome the suggestion.

Some libraries already do this mind!

Re:Things to Use Instead of JSON Web Tokens by gsylvie on Monday May 08, 2017 @02:23PM (#14294194)
Reminds me of the problem of fatal tractor rollovers on farms. Should we fix the problem with better documentation, better training, or better tractors?

http://www.sciencedirect.com/science/article/pii/S0925753596...

http://agrivita.ca/program/lowcost.php#LowCostRollOverProtec...

Re:Things to Use Instead of JSON Web Tokens by grovegames on Monday May 08, 2017 @03:41PM (#14294875)
I think all three should be used. But this isn't the question being addressed, which is whether to use tractors at all...
Re:Things to Use Instead of JSON Web Tokens by gsylvie on Monday May 08, 2017 @04:29PM (#14295298)
Even if better training or better documentation is available, how do you get the driver of the tractor to benefit from it?

The solution is better tractors. Don't blame the user.

Re:Things to Use Instead of JSON Web Tokens by dfsegoat on Monday May 08, 2017 @03:46PM (#14294912)
but why is that question being asked? because of safety / security...
Re:Things to Use Instead of JSON Web Tokens by kevinburke on Monday May 08, 2017 @11:47AM (#14292606)
I just documented how it should be done, in the article at the top of the page. The answer is "don't use JWT." Use specific tools for the thing you are actually trying to do, that have API's that are harder to mess up.
Re:Things to Use Instead of JSON Web Tokens by Minikloon on Monday May 08, 2017 @12:23PM (#14293028)
By that logic the answer is also "don't use SQL".
Re:Things to Use Instead of JSON Web Tokens by kevinburke on Monday May 08, 2017 @12:34PM (#14293132)
More like "Don't use SQL, if a thing adjacent to SQL exists that is better suited to a particular use case, doesn't have a history of poor implementations, and is harder for implementers and end users to screw up."

In this case:

- crypto_auth, or HMAC-SHA256 by itself, for authentication

- crypto_secretbox for symmetric encryption

- crypto_box or TLS for public key encryption

Re:Things to Use Instead of JSON Web Tokens by deathanatos on Monday May 08, 2017 @02:49PM (#14294405)
Good JWT libraries essentially have a "box" and "unbox" function; the work required by the client needed to go behind the library's back here is on the same level as that needed to behind crypto_box's. Further, crypto_box works on a lower level than JWT encode/decode functions typically do, and would leave many concerns that JWTs handle in the user's hands for them to handle, alone. Having the user write their own code to handle those concerns is a terrible idea.
Re:Things to Use Instead of JSON Web Tokens by mmalone on Monday May 08, 2017 @07:09PM (#14296447)
I'm with you on this. I've never thought of JWTs as a session storage mechanism; rather, I've always thought of them as a simpler (JSON-based) alternative to technologies like X.509 attribute certificates and SAML assertions. If you're creating a ticket / verifiable claim, there are a bunch of security considerations that JWT at least lays the groundwork for, and that NaCl secretbox doesn't appear to offer. Curious what OP thinks about putting things like payload canonicalization, subject/issuer/audience specification, and expiration entirely in the user's hands. I suppose its up to implementors to do appropriate validation, but at least JWT simplifies the conversation a bit.
Re:Things to Use Instead of JSON Web Tokens by wolco on Monday May 08, 2017 @01:00PM (#14293413)
But what happens is that sql version becomes sqlite and it doesn't provided enough power or flexibility.
Re:Things to Use Instead of JSON Web Tokens by rattray on Monday May 08, 2017 @01:33PM (#14293720)
> Use specific tools for the thing you are actually trying to do, that have API's that are harder to mess up.

That sounds like it would require a greater amount of knowledge to do correctly than "careful JWT".

Re:Things to Use Instead of JSON Web Tokens by kevinburke on Monday May 08, 2017 @02:20PM (#14294173)
"Careful JWT" implies you know what you should be careful about. If you know that much, you should just use the better things.

It also ignores the role JWT plays in promoting bad security practices

Re:Things to Use Instead of JSON Web Tokens by MR4D on Monday May 08, 2017 @06:10PM (#14296109)
Never underestimate the ignorance (or stupidity) of a developer under a deadline.
Re:Things to Use Instead of JSON Web Tokens by tracker1 on Tuesday May 09, 2017 @04:45PM (#14303650)
And that hasn't happened with similar authentication systems... I'd be surprised if there weren't a lot of broken OAuth/OpenAuth/OpenID systems with similar issues in the wild. Most of the issues I've seen with JWT I hadn't experienced because I hadn't thought to even allow such variety... in one case, the public key was cached from a fixed URL, and in others, shared key was forced in place.

It's only when you leave things open, or use a poorly implemented library that you have issues. It's a really easy standard to understand, and frankly most of the library implementations suck, but it's really easy to roll your own, and lock it down to the single implementation details you use internally.

Re:Things to Use Instead of JSON Web Tokens by CiPHPerCoder on Monday May 08, 2017 @08:54AM (#14291059)
> Only if you completely bungle the implementation on the server-side.

I call this "blaming the user for the designer's error-prone cryptographic designs".

The problem with JOSE (the superset of specifications that includes JWT) isn't libraries written by careless developers, the problem with JOSE is the standard itself.

https://paragonie.com/blog/2017/03/jwt-json-web-tokens-is-ba...

If in doubt, ask a cryptographer.

The problems, for people who don't want to read articles from comment links, are:

  - JSON Web Signing
    - alg headers
    - "This Header Parameter MUST be present and MUST be understood and processed by implementations."
  - JSON Web Encryption
    - RSA with PKCS1v1.5 padding (power word: Bleichenbacher 1998)
    - ECDH over NIST curves (and, in practice, invalid-curve attacks)
    - AES-GCM included in a list of asymmetric algorithm choices, for added confusion
    - AES-GCM for shared-key encryption, without guidance over nonces or key rotation
A better solution from JOSE would only give developers two options:

  - Version (v1, v2, v3, etc. which hard-coded the algorithm choices)
  - Operation
    - enc -> crypto_secretbox()
    - auth -> crypto_auth()
    - pub-enc -> crypto_box_seal()
    - pub-sign -> crypto_sign_detached()
Re:Things to Use Instead of JSON Web Tokens by deathanatos on Monday May 08, 2017 @03:20PM (#14294696)
Specifying "v1" "v2" or "v3" is not materially different than specifying the exact algorithm by name, which is what JWT does.

You (and the linked article) are selectively quoting the JWS specification too, to imply that the server needs to always handle a token presented to it, regardless of the specified algorithm; the article is misleading the reader by doing so. The RFC also states,

> Even if a JWS can be successfully validated, unless the algorithm(s) used in the JWS are acceptable to the application, it SHOULD consider the JWS to be invalid.

As for the section about "MUST be understood and processed": the standard is simply saying that implementors must use the "alg" field. You can't ignore it. Extending that to "must process anything the client sends" results in nonsense.

The suggestion to "use NaCl" ignores the entirety of JWT claims, and foists implementation of that functionality onto every single consumer that needs them. (And you hope that they recognize that they need them.) Centralizing implementations of cryptographic code into a few, well-vetted implementations is better than just throwing our hands up and telling the community to fend for themselves. While some JWT implementations had bugs in the past, these same bugs could easily be present in the custom implementations of your proposal, of which there would be many.

Re:Things to Use Instead of JSON Web Tokens by tptacek on Monday May 08, 2017 @03:29PM (#14294780)
You're missing the distinction between algorithms, which rarely have flaws, and protocol constructions, which often do.

Algorithm negotiation within an otherwise static protocol incurs complexity, which has a security cost. Just as importantly, it doesn't address the real origin of cryptographic protocol flaws. Note how, in order to correct cryptographic flaws in TLS, we had to push people first from SSL3 to TLS 1.0, and then later to TLS 1.1.

Re:Things to Use Instead of JSON Web Tokens by deathanatos on Monday May 08, 2017 @05:50PM (#14295950)
Certainly it does, but what would you suggest JWT do differently? One can't realistically hard-code the algorithm(s) in use: that would prevent any ability down the road to upgrade to a better set.
Re:Things to Use Instead of JSON Web Tokens by tptacek on Monday May 08, 2017 @06:00PM (#14296025)
Once again:

1. "Hard-code" the simplest possible sound crypto construction that solves the specific problem the protocol is meant to solve.

2. Put a version on the whole protocol.

3. If the crypto constructions later need to be amended, upgrade the whole protocol.

The anti-pattern is attempt to use a static "outer protocol" with a negotiated and regularly changing "inner protocol" --- that's an architecture we know from experience does not work well.

You know you're in trouble when developers are forced or even encouraged to make decisions between things like RSA and ECC.

Re:Things to Use Instead of JSON Web Tokens by CiPHPerCoder on Monday May 08, 2017 @03:24PM (#14294733)
From https://news.ycombinator.com/item?id=14292223

> * Flaws in crypto protocols aren't exclusive to, but tend to occur mostly in, the joinery of the protocol. So crypto protocol designers are moving away from algorithm and "cipher suite" negotiation towards other mechanisms. Trevor Perrin's Noise framework is a great example: rather than negotiating, it defines a family of protocols and applications can adopt one or the other without committing themselves to supporting different ones dynamically. Not only does JWT do a form of negotiation, but it actually allows implementations to negotiate NO cryptography. That's a disqualifying own-goal.

My proposal replaces the joinery with "select a version". You don't get to mix-and-match primitives. You won't fall into the trap of Reasoning By Lego.

> Centralizing implementations of cryptographic code into a few, well-vetted implementations is better than just throwing our hands up and telling the community to fend for themselves.

I'm not throwing my hands up and saying "fend for yourselves". I've outlined what needs to be changed to make it secure, and said I'll write a formal spec when I have the time, as keeping a roof over my family's head takes precedence over doing a lot of thankless unpaid work.

Re:Things to Use Instead of JSON Web Tokens by deathanatos on Monday May 08, 2017 @05:47PM (#14295924)
This is a much better point (or perhaps a much better way of stating it) than what I got from your original post.

I agree wholehearted that you don't want to give the end-user mix-and-match primitives. But I don't think that JWT really gives you that, at least at the level I think you're discussing. For example, JWT doesn't let you choose an asymmetric cipher and a hash algorithm; you have to choose a precomposed whole, such as "RS256" (RSA w/ SHA-256) or "HS256" (HMAC w/ SHA-256). To me, this seems equivalent to NaCl, in a sense. In JWT, I must choose one of "RS256", "HS256", etc. In NaCl, I must choose one of the crypto_* functions. Are these not both giving the user equivalent choices between equivalently pre-composed functionality? (Are you simply saying that the JWT standards offer too many choices between essentially equivalent cryptographic combinations, such as multiple choices for HMAC or RSA, and/or that you disagree w/ the exact combinations offered?)

> I've outlined what needs to be changed to make it secure, and said I'll write a formal spec when I have the time

Perhaps it's what you're leaving unsaid, but the gist I get from your proposal is that you're discarding the entirety of JWT's claims section, essentially equating a JWT with an authenticated and potentially encrypted message; i.e., the output of the NaCl functions that you present.

Re:Things to Use Instead of JSON Web Tokens by rattray on Monday May 08, 2017 @01:37PM (#14293750)
So, as suggested above, come up with a standard that encodes that subset – "Iron-JWT" or what have you.

Much easier for adoption to use a "better version" of the widely-used tool you're already using than some newfangled thing that a guy on HN said was more secure.

Re:Things to Use Instead of JSON Web Tokens by CiPHPerCoder on Monday May 08, 2017 @01:58PM (#14293963)
I've previously made my proposal to the JOSE IETF mailing list. The participants just held their nose up to it.

https://www.ietf.org/mail-archive/web/jose/current/msg05621....

https://gist.github.com/paragonie-scott/c88290347c2589b0cd38...

When I'm not dealing with client work, I'll write a replacement for JOSE that has the properties I outlined above. Until I find the free time for this, things that increase my income take precedence.

Re:Things to Use Instead of JSON Web Tokens by yuhong on Monday May 08, 2017 @02:44PM (#14294366)
Notice that they did not include JWT in this!
Re:Things to Use Instead of JSON Web Tokens by CiPHPerCoder on Monday May 08, 2017 @02:50PM (#14294413)
JWT uses JWS, JWE, or both. Any criticism that targets JWE and JWS is necessarily relevant to JWT.

The problems with JWT being addressed are in the domain of cryptography designs, so it's natural to criticize the cryptography components.

The other problem with JWT is how people use it: http://cryto.net/~joepie91/blog/2016/06/13/stop-using-jwt-fo...

Re:Things to Use Instead of JSON Web Tokens by yuhong on Monday May 08, 2017 @03:09PM (#14294592)
The point however is that JWS/JWE is not as flawed as JWT is.
Re:Things to Use Instead of JSON Web Tokens by CiPHPerCoder on Monday May 08, 2017 @03:11PM (#14294618)
Yes it is. Most of the problems people point to with JWT exist in JWS or JWE.
Re:Things to Use Instead of JSON Web Tokens by eriknstr on Monday May 08, 2017 @07:34AM (#14290725)
>JSON Web Token

Thanks, I didn't know what JWT meant. When I first read the title I thought it would be about the Google Web Toolkit (GWT) which I incorrectly remembered as being named Java Web Toolkit (JWT) because with GWT you use Java.

Author would do well to edit their post, changing the title to "Things to Use Instead of JSON Web Tokens" and replacing the first occurrence of "JWT" in the body text with "JSON Web Tokens (JWT)".

In addition to helping visitors from HN, this change could also improve the possibility for others to find the text in the future when they search for JSON Web Tokens using a search engine.

Re:Things to Use Instead of JSON Web Tokens by mmmpop on Monday May 08, 2017 @01:19PM (#14293602)
To make it more fun, people say JWT as "jot" which sends me into a blind rage.
Re:Things to Use Instead of JSON Web Tokens by Freak_NL on Monday May 08, 2017 @01:27PM (#14293665)
I can imagine. Unfortunately, "jot" is the formal pronunciation of JWT…

Makes me glad me and my colleagues are Dutch; we just pronounce the names of the three letters in Dutch — yaywaytay.

Re:Things to Use Instead of JSON Web Tokens by mmmpop on Monday May 08, 2017 @01:40PM (#14293786)
I prefer that pronunciation too!
Re:Things to Use Instead of JSON Web Tokens by devrandomguy on Monday May 08, 2017 @04:24PM (#14295254)
Let's try "Ja'wut". As in "'thentikayshun? Ja, wut am I gonna use for that?"
Re:Things to Use Instead of JSON Web Tokens by wvh on Monday May 08, 2017 @07:37AM (#14290742)
I guess the general problem with security is that developers use libraries (and frameworks) so as to not have in-depth understanding of the functionality that library provides. That becomes an issue when the library doesn't provide sane defaults or too many options, i.e. ways to shoot yourself in the foot by choosing bad options either by own choice or by programming error – relying on malicious client input.

Libraries that provide one solid hard-coded implementation based on current best practices are a much better idea for most projects, but of course what then with giant specs like Oauth and OpenID Connect...

Re:Things to Use Instead of JSON Web Tokens by gant on Monday May 08, 2017 @05:51AM (#14290342)
OP literally just deleted a bunch of files from the repo and then went out of his way to break compatibility with normal JWT HS256 tokens by changing the typ and removing the alg argument. If you wanted to pull out other algos from jwt-go, deleting their implementations would've been entirely sufficient. There is a map that holds a alg-string to implementation that would've ended up with only HS256.

Instead OP made sure these tokens can't be used outside their fork, and thus only in Go.

ISHYGDDT.

Re:Things to Use Instead of JSON Web Tokens by skrebbel on Monday May 08, 2017 @06:03AM (#14290389)
> ISHYGDDT

For readers like me, this means "I seriously hope you guys don't do this."

Re:Things to Use Instead of JSON Web Tokens by badosu on Monday May 08, 2017 @06:39AM (#14290519)
Thanks for the information, I find that these acronyms may increase the bandwidth of communication, but the worse quality of the prose and dependence of context that is not always obvious makes this pattern very annoying.

I've read this one specifically many times without knowing what it means, whereas the author may think that an interested reader would look up it's meaning, in my case I rejected what I read and moved on.

Re:Things to Use Instead of JSON Web Tokens by zyx321 on Monday May 08, 2017 @08:33AM (#14290968)
ISHYGDDT is 4chan slang. It's deliberately obtuse. You're not supposed to look it up, you're supposed to LURK MORE until you figure it out from context.

Even if you do know what it stands for, that's still only half of the true meaning.

EDIT: By which I mean this sort of language is not a good fit for an audience that doesn't follow 4chan memes.

Re:Things to Use Instead of JSON Web Tokens by always_good on Monday May 08, 2017 @10:08AM (#14291558)
Yeah, let's please keep this childish nonsense off of HN.

    > Even if you do know what it stands for, that's 
    > still only half of the true meaning.
I cringed.
Re:Things to Use Instead of JSON Web Tokens by zyx321 on Monday May 08, 2017 @12:51PM (#14293322)

    >I cringed.
Thank you for your valuable contribution.
Re:Things to Use Instead of JSON Web Tokens by gant on Monday May 08, 2017 @06:24AM (#14290470)
Working as intended.
Re:Things to Use Instead of JSON Web Tokens by IshKebab on Monday May 08, 2017 @08:09AM (#14290867)
> Only if you completely bungle the implementation on the server-side.

Did you even read that article?

> You could imagine excuses being made about the people who died, or lost their fingers or hands; they were inattentive, they weren't following the right procedure, bad luck happens and we can't do anything about it, etc.

"You only die if you completely bungle the coupling."

Re:Things to Use Instead of JSON Web Tokens by dmix on Monday May 08, 2017 @08:51AM (#14291046)
> "You only die if you completely bungle the coupling."

That analogy would only really make sense if JWT was always a risk unless the developer set it up properly. But the reality is that the majority of JWT libraries are up to date and don't contain the implementation flaws mentioned.

We could tell users to never use a specification because sometimes they might use a library that wasn't implemented right. But there are legit usecases for JWT that the alternatives don't 100% cover and the risks are entirely manageable.

So I agree that instead the advice should be "use responsibly", which means use a popular, up-to-date, and well vetted library. All web security authentication options comes with advice like this - just look at OWASP.

Unless the state of JWT libraries is terrible, this isn't a big thing to ask. From my experience in two languages (Ruby/Node) there have been high-quality JWT libraries available where the maintainer has stayed on top of known implementation issues with JWT.

Eventually JWT libraries in each major language will mature (if they haven't yet already?) and the risks will be quite minimal. The industry (train operators) aren't ignoring the risks here and letting people die... it seems to me that the library authors are adapting.

Re:Things to Use Instead of JSON Web Tokens by kevinburke on Monday May 08, 2017 @09:05AM (#14291121)
one of the Node libraries has a TODO that says "validate X.509 certificates"

the client gets to choose what algorithm they want to use

Re:Things to Use Instead of JSON Web Tokens by davewritescode on Monday May 08, 2017 @12:04PM (#14292801)
This is so annoying, because one person implements a shitty JWT library the whole spec stupid and should be avoided? Tell that to Amazon, Microsoft, Facebook and and implementer of OpenID Connect. Somehow, they've all figured out use cases where JWT makes sense and it hasn't been a security nightmare.

JWT.io has a comprehensive list of not shitty implementations of JWT. It's literally the first page I see when I google JWT.

Re:Things to Use Instead of JSON Web Tokens by kevinburke on Monday May 08, 2017 @12:29PM (#14293084)
point to similar errors being made routinely by Nacl or libsodium implementations, and I'll give you a pass here
Re:Things to Use Instead of JSON Web Tokens by derefr on Monday May 08, 2017 @03:27PM (#14294763)
JOSE/JWT is a standard for a wire protocol encoding and format.

NaCl/libsodium are single libraries with FFI wrappers in various languages.

Comparing the two is like trying to decide on the quality of the DirectX vs. OpenGL APIs, by the quality of their implementations. If you've only got one library (DirectX, libsodium), and you're throwing a lot of users at it, it's probably going to be pretty solid whether or not its API is designed well. If you've got a lot of implementations (OpenGL, JOSE/JWT), you'll probably get some crap implementations, just by the fact that there will be "core implementations" that get used+tested in production, and then "edge implementations" that were just written to scratch one guy's itch and have no battle-hardening.

You can argue, separately, that anything with crypto elements like JOSE/JWT has should be absorbed into some high-level crypto abstraction framework like NaCl/libsodium, so that it can also benefit from there just being one high-level implementation of it.

But JOSE/JWT is a lot more than crypto; for one thing, it's also JSON. Do you want there to be a JSON parser in libsodium, the way there's an ASN.1 parser in OpenSSL? This is the path that lead OpenSSL to its current "everyone uses it for everything but it's so bloated that you can flip over any random rock and find a bug" state.

Re:Things to Use Instead of JSON Web Tokens by kevinburke on Monday May 08, 2017 @04:45PM (#14295423)
it sounds like you're trying to suggest that the idea being proposed by the JWT specification is not good