Fork me on GitHub
#clojure
<
2024-04-19
>
Arthur Caillau08:04:18

👋 What do people use for login/authentication in clojure web apps these days? Session based cookies, JWT? I am curious to also have some feedback on some vendors like Auth0, AWS Cognito, etc.

Ivar Refsdal08:04:59

We use JWT in a localstore and a cookie that stores a JWT (two different systems). Tip for library for validating JWT: https://github.com/sikt-no/clj-jwt (shameless plug? I am involved in that project.)

p-himik08:04:01

You should stick to the lowest surface area that satisfies your needs. I'd go out on a limb and say that as much as 90% of all websites can work without any issues with the simplest session based cookies.

2
p-himik08:04:56

If you have a database and don't have distributed web services or thirdparty auth, then session cookies are the way to go. Use a 128-bit random number (be sure to set -Djava.security.egd=file:/dev/urandom) as a session ID , store it in a secure cookie on the client side and in a session table in your DB using that very number as its primary key. That's it, job done. At least, when it comes to sessions themselves - you still need password hashing and validation and most likely other somewhat tangential things, like CSRF tokens.

Felipe10:04:14

I enjoyed this http://fly.io blog post last time I had the same question: https://fly.io/blog/api-tokens-a-tedious-survey/

p-himik10:04:42

Ah, glad the author of the article and I agree on the matter. :)

p-himik10:04:36

Oh, wait - it's by tptacek. Of course we agree - I've gotten most of my auth knowledge by reading his articles and comments, lol.

valerauko10:04:08

Session based cookies, JWT?Both. Short lived JWTs and a session cookie for renewing said JWT (JWT with everything pinned though so there's no negotiation involved)

p-himik07:04:00

Just in case you missed it, I explicitly wrote that we're in agreement. :) And no, my goal is not to argue against everything. When someone says "you should use X", I expect them to be able to know accurately and precisely why I should be using X. Especially when the crux of the original question is about auth in web apps, without any additional requirements whatsoever.

p-himik07:04:03

And just in case that article by Thomas Ptacek (an actual professional security researcher, not some random guy on the internet, with experience in his domain almost as long as my life) got lost in all our chit-chat (sorry, folks), I'll let myself quote the most relevant part: > Frankly, the biggest knock against simple random tokens is that they’re boring. If you can get away with using them — and most applications can — you probably should. Give yourself permission by saying you’re doing it for security reasons. Security is a problem for all the fancy tokens [...] That's exactly what my point has been in this thread. And he has no money in saying that.

Arthur Caillau17:04:58

Thanks guys for sharing your experience on this topic :hugging_face: And I am sorry the arguments heated up a little bit.

Hendrik09:04:37

Very interesting discussion 🙂 one more point about random tokens: would you store them directly or would you store a hash of the token? the reason is the same as for passwords: on a db leak an attacker could get access to all user accounts

p-himik10:04:44

Quoting https://news.ycombinator.com/item?id=16006394: > We hash passwords because passwords are valuable across sites; it's a big deal to compromise someone's password, even on a random low-value application. That's not true of API keys. If your database is compromised, the API keys don't matter anymore. Don't bother encrypting them. > You also won't find any advice to encrypt session IDs on the OWASP website. What is advised on this matter is to re-require pwd auth before doing sensitive things and timing sessions out.

👍 2
Vi11:04:44

Hello! I'm a bit confused. I use deps.edn in a project and use cognitect-labs/test-runner for tests. Also I have few java files that need to be used. Is it possible to compile java files before tests runs and load its by a single cli command in pipeline? (I've compiled its but (:import ..) can't find classes. Some misunderstanding with classLoader?)

Ed12:04:55

You can use tools.build (https://clojure.org/guides/tools_build#_mixed_java_clojure_build) to compile the java code before the clojure code. You can also use something to orchestrate the tasks, like babashka tasks (https://book.babashka.org/#tasks) or make.