Live data from Hacker News

How to Use JSON Web Tokens

github.com

61–70 of 135 posts

Re: How to Use JSON Web Tokens

#61
post #2

JWTs are radioactive. Proceed with caution.

This meme is getting out of hand. Yes, JWTs may be inappropriate compared to putting a session id in a cookie, but there are many uses for JWTs outside of web app session handling. There are a couple serious implementation pitfalls to be aware of, but the bottom line is that JWT is a convenient and standardized way to construct a secure bearer token. Despite the pitfalls, most folks that need a bearer token format (n…

The number of projects that truly "need a bearer token format" is roughly the same as the number of projects that truly "need a blockchain".

Re: How to Use JSON Web Tokens

#62
post #38
post #2

JWTs are radioactive. Proceed with caution.

They're a complicated solution to a problem that you almost certainly don't have. Storing session data in a private datastore using a long random session identifier as the key is simpler, more secure, and more flexible than JWT.

That's the conclusion I've come to. I wished someone would have saved me a few brain cells and told me that when I first heard about the damn things.

Re: How to Use JSON Web Tokens

#63
post #22

Maybe in 2019 we'll stop using JSON/JS for everything

Your wish has been granted. 2019 is the year of YAML as a serialization format and the return of CoffeeScript. Disclaimer: I am a genie.

Can we go back further and have Django/Rails as the new hotness with Pjax/Turbolinks for the extra cool kids?

Re: How to Use JSON Web Tokens

#64
post #3

Earlier quoted context omitted.

I keep hearing this. Is there a good writeup available?

tptacek posted some good commentary on this a while back - https://news.ycombinator.com/item?id=14292223

This is the best explanation I've seen. I think many commenters mean to say something similar but don't give enough context. Here's my phrasing of what I take away from tptacek's comment:

JWT is designed to be customized for a variety of use cases, which means programmers using JWT are rolling their own security scheme, including choosing cryptography from a practically unrestricted field of options. This is known to be a recipe for disaster. A good standard should provide an expert-validated scheme for a specific use case that gives end programmers assurance that if they comply with the standard, the scheme will fulfill its intended use case. This means standardizing separate use cases separately; therefore, JWT is at best a technology that experts could use (but probably wouldn't) to devise specific standard solutions for specific use cases which would then be appropriate for end programmers to use.

Re: How to Use JSON Web Tokens

#65
post #55

Earlier quoted context omitted.

> 1) They are signed not encrypted. Anything you put in there is public readable, unless you encrypt your token after you generate it Not a JWT expert but isn't this the point of a JWT or am I missing something. Sharing data between servers & clients while being able to make sure the data wasn't changed. > 2) you can accept a range of encryption types, don't. Stick to one type and disallow any token that doesn't conf…

> Sharing data between servers & clients while being able to make sure the data wasn't changed. I think the main use is sharing data between the server and itself. The client shouldn’t depend on the internal structure of the token. The token should just be issued by the server to the client, and the client passes it along to subsequent requests to the server.

Both good points!

Re: How to Use JSON Web Tokens

#66

Earlier quoted context omitted.

As mentioned in the article you might want the token to be read by the users. Such as issuing a token with a expiry date that you want the user to regenerate. Although If anything the JWT libraries should have encryption enabled by default.

It can also be helpful if: - your system is distributed - you don't want to be keeping a decryption key secure and in-sync across many (and potentially less-trusted) nodes - the JWT contains attributes useful to the system (e.g. role, user ID, etc.) You'll probably still be keeping track of a public key of whatever's signing it (to verify authenticity), but that isn't a secret. And then you can still securely trust

> your system is distributed

if you don't have a shared data store, or its not fast enough, then you're doing the wrong thing with the wrong tools

> you don't want to be keeping a decryption key secure and in-sync across many (and potentially less-trusted) nodes

keeping shared secrets, which are very high read:write ratio, and change daily or less, should be childs play. If its not, then your security protocols are wrong. Key rotation must be simple and quick if you want your system to scale. When you get to 100 people, you'll be leaking keys weekly.

KMS, Vault and a few others are your friend here. There are off the shelf systems for this.

> the JWT contains attributes useful to the system (e.g. role, user ID, etc.)

having these public can be alright, assuming that you've properly mapped, scrubbed and checked for leakage. However, you shouldn't be reliant on user supplied stuff for this. You simply cannot trust the user.

If you need jwt for caching data, then you have a much bigger architectural problem. The stuff you are storing in JWT needs to be easily and quickly accessed. If its not, you either have a DB or a messaging system issue.

Now, if you are encrypting the whole token, then its less of an issue. But, using it to store anything other than a UUID and a issue time, you are asking for trouble.

Re: How to Use JSON Web Tokens

#67

JWTs are useful, but there are a few things that are not immediately obvious. 1) They are signed not encrypted. Anything you put in there is public readable, unless you encrypt your token after you generate it 2) you can accept a range of encryption types, don't. Stick to one type and disallow any token that doesn't conform (this protects against people making their own tokens with 'None' as the signing algorithm) I…

[deleted]

Re: How to Use JSON Web Tokens

#68
post #56

Earlier quoted context omitted.

My issue here is that expiring JWTs involve adding state! The whole point of JWTs is stateless authentication, so I’ve never understood the advantage over sessions unless revoking tokens is never an option.

When are you expiring tokens ahead of their natural expiration date? When someone logs out? Isn’t that state? If you add state to something stateless you are generally on your own. [edit: also I disagree with the notion that something with an expiration date is stateless. It has two states. It’s just that the look like idenpotence]

When someone's account is compromised, is another situation.

Re: How to Use JSON Web Tokens

#69
post #53

Earlier quoted context omitted.

To be clear, cookies are an HTTP header field that can carry any text data you want. You can pass plain text, JWTs or any other encrypted payload (which many web frameworks do automatically). JWTs aren't comparable to cookies, they're just a standard way to sign data.

His or her point was that if you don't sign and/or encrypt, there's no benefit over a standard cookie.

not sure if that was the point or not, but it's wrong. even if you did sign/encrypt, that's not a benefit over a standard cookie. you can easily sign or encrypt a 'standard cookie' as well.

the benefit is the portability that comes from a standardized and widely used data structure.

Re: How to Use JSON Web Tokens

#70
post #61

Earlier quoted context omitted.

This meme is getting out of hand. Yes, JWTs may be inappropriate compared to putting a session id in a cookie, but there are many uses for JWTs outside of web app session handling. There are a couple serious implementation pitfalls to be aware of, but the bottom line is that JWT is a convenient and standardized way to construct a secure bearer token. Despite the pitfalls, most folks that need a bearer token format (n…

The number of projects that truly "need a bearer token format" is roughly the same as the number of projects that truly "need a blockchain".

That is not remotely true.
Post reply on HN