News for hackers. Stuff that matters.
Re:Hardcoded secrets, unverified tokens, and other common JW... by afandian on Saturday June 27, 2020 @07:43AM (#23661180)
These failure modes have been used to criticise JWT over the years. But all of these errors are of the same level as "don't concatenate input strings into SQL strings" or "don't store passwords in plain text". That these errors are made says much, but not about the technology, IMHO.
Re:Hardcoded secrets, unverified tokens, and other common JW... by Znafon on Saturday June 27, 2020 @08:05AM (#23661277)
At least those are well known, no common web framework will save password in clear text, and there is comprehensive literature on how to use SQL and many well written ORMs that will make it very hard to shoot yourself in the foot.

For JWT, it's essentially promises of easy authentication process (rarely talking about the hard things like logout) spread like landmines over Medium and blogs, waiting to blow your foot and all your application with it.

Re:Hardcoded secrets, unverified tokens, and other common JW... by mooreds on Saturday June 27, 2020 @09:56AM (#23661858)
Regarding logout, I think that's a fundamental issue with a stateless solution like JWTs. I mean, the whole point is that it is a self encapsulated token, so you don't have to go back to a central server to check if someone's login session is still valid. So how on earth do you invalidate it?

My boss wrote up this article on different ways to revoke JWTs: https://fusionauth.io/learn/expert-advice/tokens/revoking-jw... which examines a few interesting methods.

Re:Hardcoded secrets, unverified tokens, and other common JW... by dathinab on Saturday June 27, 2020 @11:54AM (#23662569)
For many applications "slow" logouts are enough, i.e. basically do what is common in OAuth2 setups:

- Have a refresh token which is only usable with the (right) auth server and can only be used to generate new access tokens. As it's only usable with the auth server it's easy to revoke (it's kinda like a session cookie).

- Keep validity of access tokens short.

So by revoking the refresh token the logout will be done in at most highest_refresh_token_start_time + refresh_token_validity.

Through sadly any "faster" logout method on a distributed system is indeed quite complex. (Like propagating bloom filter headed blacklists of early revoked access tokens).

Re:Hardcoded secrets, unverified tokens, and other common JW... by Znafon on Saturday June 27, 2020 @12:53PM (#23662928)
> For many applications "slow" logouts are enough

Why? I understand it might be acceptable for the next "Uber for Cats" SaaS but if you protect an account that is actually important, not being able to revoke an access key is an issue.

> Keep validity of access tokens short.

But then you are actually spamming your authentication service and it even starts to blur the distinction between access token and refresh token.

I understand that there is many specific use cases where JWT makes sense like when you have to delegate authentication but for other case which shouldn't be recommending it, not being able to properly logout is not a security practice we should have in 2020 and later.

Re:Hardcoded secrets, unverified tokens, and other common JW... by user5994461 on Saturday June 27, 2020 @03:05PM (#23663870)
What better tool do you suggest that can handle logout? It's 2020 and there are none.

OpenID Connect with JWT handles logout just fine if you really want it. Call the /oidc/tokeninfo to check the token is valid instead of verifying the signature offline. Of course this doesn't have the benefits of a decentralized token anymore. Can't have the cake and eat it too.

Re:Hardcoded secrets, unverified tokens, and other common JW... by nextaccountic on Saturday June 27, 2020 @03:24PM (#23663989)
Doing regular, boring authentication using user/password just supports logout out of box.
Re:Hardcoded secrets, unverified tokens, and other common JW... by poxrud on Saturday June 27, 2020 @03:40PM (#23664096)
So regular cookie session based auth? There are drawbacks such as managing session state on the server, and increased latency and cpu load, since you now have to have a db call on every action.
Re:Hardcoded secrets, unverified tokens, and other common JW... by closeparen on Saturday June 27, 2020 @04:05PM (#23664256)
The argument is that this DB call, or something much like it, is inherently necessary to support logout. It's not something unnecessary that can be optimized away; getting rid of it entails losing functionality.
Re:Hardcoded secrets, unverified tokens, and other common JW... by tester756 on Saturday June 27, 2020 @04:44PM (#23664542)
>rarely talking about the hard things like logout

Why hard?

You can always black list them

Re:Hardcoded secrets, unverified tokens, and other common JW... by synthc on Saturday June 27, 2020 @07:32PM (#23665564)
But then you have have make a database call to check the blacklist, so you might as well use sessions
Re:Hardcoded secrets, unverified tokens, and other common JW... by tester756 on Saturday June 27, 2020 @07:49PM (#23665647)
I'm not sure about it, but what if Logout just removed token from client meanwhile "Logout from all devices" black lists token?

I tend to believe that it could be used by gmail, but it's just a guess

Re:Hardcoded secrets, unverified tokens, and other common JW... by poxrud on Saturday June 27, 2020 @08:06PM (#23665713)
If you're blacklisting tokens at any point in your application, you then need to check this blacklist.
Re:Hardcoded secrets, unverified tokens, and other common JW... by dcbadacd on Saturday June 27, 2020 @07:53AM (#23661225)
It goes into the same category as criticizing C's memory safety. The errors do say a lot about the tech being prone of misuse, and that's not really a good thing.
Re:Hardcoded secrets, unverified tokens, and other common JW... by XMPPwocky on Saturday June 27, 2020 @02:48PM (#23663777)
"don't concatenate input strings into SQL strings" is a pretty good comparison, because the rise of ORMs and APIs that make parameterized queries ergonomic has done probably 10 times as much to stop SQLi in practice as telling developers to sanitize their inputs ever did.
Re:Hardcoded secrets, unverified tokens, and other common JW... by tester756 on Saturday June 27, 2020 @04:43PM (#23664528)
>sanitize their inputs ever did.

was even escaping input viable strategy?

if you escape thing, then your data in db is broken

parametrization seems like the only strategy out of those 2

Re:Hardcoded secrets, unverified tokens, and other common JW... by corty on Saturday June 27, 2020 @04:57PM (#23664636)
some parts of a query cannot be parameterized, e.g. the column name for an 'order by' in many cases. So you have to do some kind of escaping, sanitation and concatenation.
Re:Hardcoded secrets, unverified tokens, and other common JW... by namibj on Sunday June 28, 2020 @03:26AM (#23667243)
If you're escaping/sanitizing to massage an input string until you can concatenate it into a SQL query, you're doing it wrong. Please don't.
Re:Hardcoded secrets, unverified tokens, and other common JW... by tester756 on Saturday June 27, 2020 @07:51PM (#23665653)
While this solution isn't sexy, cannot it be just simple switch?

switch(int)

case 1: age

case 2: salary

Re:Hardcoded secrets, unverified tokens, and other common JW... by corty on Sunday June 28, 2020 @03:32AM (#23667270)
Yes, unless the database has custom column names e.g. to add your own properties to some object. But that kind of schema is madness in other aspects as well...
Re:Hardcoded secrets, unverified tokens, and other common JW... by namibj on Sunday June 28, 2020 @03:25AM (#23667240)
I have yet to dream up/see a case where you can't puzzle literals together based on user-query parsing until you get your SQL query assembled.
Re:Hardcoded secrets, unverified tokens, and other common JW... by afandian on Saturday June 27, 2020 @04:17PM (#23664337)
Agreed. But writing your own authentication frameworks are a virtually identical situation.
Re:Hardcoded secrets, unverified tokens, and other common JW... by danjac on Saturday June 27, 2020 @08:40AM (#23661460)
An authentication protocol that has this many footguns and insecure defaults is probably just not a very good authentication protocol.
Re:Hardcoded secrets, unverified tokens, and other common JW... by mooreds on Saturday June 27, 2020 @10:04AM (#23661902)
That's similar to saying that CRUD apps are bad because you can have SQL injection (as others have mentioned). Or that username/password is a "not very good authentication protocol" because some folks store passwords in a database in plaintext. Sure, the "none" algorithm is a footgun, but just make sure you don't allow it.

Maybe I'm talking my book (because I work for a company that sells software which generates JWTs) but I think it isn't that hard to securely validate them. It's just matching on JSON keys, mostly, and can be wrapped up in a library (like https://github.com/jwt/ruby-jwt).

I also wrote an article on how to build secure JWTs: https://fusionauth.io/learn/expert-advice/tokens/building-a-...

I guess the question is, where's the balance between the responsibility of the application developer vs the RFC authors? That's an interesting discussion to have, because I bet there is at least one valid use case for every one of the JWT RFC sections. (I've even heard of valid cases for the "none" algo, like if you are very concerned about performance and have other ways of validating your clients, such as mutual TLS certs.)

I've never written an RFC/standard, but I bet it isn't an easy task.

Re:Hardcoded secrets, unverified tokens, and other common JW... by polymeris on Saturday June 27, 2020 @10:29AM (#23662039)
That's the thing, JWT is not an authentication protocol, that's just one (the most frequent) use-case of "transfering claims". The footguns, e.g. the choice of encrypted or not, or symmetric or asymmetric crypto, are a result of the flexbility required to cover the other use-cases. Maybe what's needed is a subset of JWT that's just for AuthN.
Re:Hardcoded secrets, unverified tokens, and other common JW... by user5994461 on Saturday June 27, 2020 @09:20AM (#23661698)
Irrelevant. If the application doesn't call the function to verify the user token, the application is insecure, it doesn't matter what protocol or token format is used.
Re:Hardcoded secrets, unverified tokens, and other common JW... by chriswarbo on Saturday June 27, 2020 @10:41AM (#23662119)
My response to that would be "Parse, don't validate" ( https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va... ).

In other words "the function to verify the user token" should also return the payload data (e.g. the user ID, or whatever), and it should ideally be the only way to get that payload data. That way there's very little that can go wrong:

- If the verification function doesn't get called, then the application doesn't get its payload data (e.g. user ID), and hence can't be misusing that data.

- If the application is using the payload data, then it must have come from the verification function, and hence has been validated.

I'm adding JWTs to a system right now, and forcing this interface by encrypting all of the payloads. The only system with access to the decryption key will refuse to decrypt tokens which aren't signed, valid, non-expired, etc.

Re:Hardcoded secrets, unverified tokens, and other common JW... by andybak on Saturday June 27, 2020 @09:53AM (#23661849)
You ignore the fact that some protocols are easier to "do wrong" than others. The point other people are making is that JWT is one of those.

You're welcome to disagree but don't gloss over the fundamental point being made.

Re:Hardcoded secrets, unverified tokens, and other common JW... by rileymat2 on Saturday June 27, 2020 @09:29AM (#23661737)
To play devils advocate say the design by the library was that you could not read the jwt data without the library verifying it.

That goes away.

Re:Hardcoded secrets, unverified tokens, and other common JW... by VzQDfUbMbhuJJT7 on Saturday June 27, 2020 @09:19AM (#23661689)
What would you suggest instead?
Re:Hardcoded secrets, unverified tokens, and other common JW... by SpicyLemonZest on Saturday June 27, 2020 @08:10AM (#23661293)
Ultimately, everyone has a first time working with some particular technology. If doing the right thing requires knowing specific coding patterns, there'll be a lot of cases where people do the wrong thing.
Re:Hardcoded secrets, unverified tokens, and other common JW... by afandian on Saturday June 27, 2020 @08:39AM (#23661457)
Of course you can improve the tooling but it's not the only conclusion.

If you don't read the docs, don't have the right mentoring, etc etc, your first go at anything is likely to be of low quality. Calibrate your confidence better, especially for anything security-related. Don't put it into production if you've only skimmed the docs (the mistakes we're talking about are novice mistakes).

Another conclusion you could draw is "use a built in security library not raw JWTs". There's just as much reason not to use a security library as there is not to use a SQL ORM.

Re:Hardcoded secrets, unverified tokens, and other common JW... by thdrdt on Saturday June 27, 2020 @09:04AM (#23661599)
But doesn't JWT sometime force people to use it in an insecure way because of how it is designed?

In a JavaScript browser app without backend server it is impossible to use it safe. The token must be visible to JavaScript which is unsafe by default.

You also need to store both the token and refresh token in your app which makes the refresh safety feature useless.

I still don't get JWT. It solves requesting an auth server all the time but when the token is stolen it can be used until it expires. This can be solved by setting the expiration very low but then the auth server is still requested all the time.

Re:Hardcoded secrets, unverified tokens, and other common JW... by user5994461 on Saturday June 27, 2020 @09:18AM (#23661683)
The only insecure-by-design authentication scheme is passing the user identifier through HTTP headers (it's unfortunately quite common). Headers are set by the web client, so any client can assume to be anyone.