News for hackers. Stuff that matters.
Re:Three things to never build yourself: auth, notifications... by rgbrenner on Thursday May 13, 2021 @02:53PM (#27145842)
Never outsource Auth. Maintain control over user accounts. That's the life blood of your business. If you have to ask everyone to reset their password because your auth provider increases their pricing or goes out of business, the churn will likely kill your company.

I would say the same for Stripe, but at least they'll help you migrate off their platform. Auth providers cant help you because the passwords are hashed... You need the same algo or you cant authenticate using the data they have.

And the only way off without a mass password reset is a silent migration in the background: migrate the user when they login.. but we all know that will take months and you will never get 100% to login during the migration period.

Pick an auth provider and you better believe in their business as much as your own. You will incur damage when you leave.

Re:Three things to never build yourself: auth, notifications... by mooreds on Thursday May 13, 2021 @03:04PM (#27145992)
You can also choose to self host. Keycloak and FusionAuth (disclosure, I am an employee) let you self host. You then have the user database in your systems.

> And the only way off without a mass password reset is a silent migration in the background: migrate the user when they login.. but we all know that will take months and you will never get 100% to login during the migration period.

Actually, not true. I can't speak for every auth provider, but FusionAuth and Auth0 both let you have the password hashes. If you know the algo (ask your provider!), you can load the hashes (and other ancillary password data like the salt) and your users will never be the wiser.

Here's a guide I wrote about how to migrate off of Auth0: https://fusionauth.io/docs/v1/tech/guides/auth0-migration/ The end goal of the guide is to move to FusionAuth, but the steps to get your password hashes out of Auth0 (the 'Exporting Users' section) will work no matter where you migrate to.

Re:Three things to never build yourself: auth, notifications... by sixhobbits on Thursday May 13, 2021 @05:11PM (#27147524)
+1.

I maintained and extended a self rolled auth system built on top of django and it was a constant headache. We lost weeks of engineering productivity fighting with keeping the various libraries up to date and running into the usual "forgot password" edgecases.

I spent a few days with FusionAuth for a demo project and once I grokked it I really wished we had used it or something similar instead. Amazing abstraction layer to have at your disposal.

Re:Three things to never build yourself: auth, notifications... by rvense on Thursday May 13, 2021 @03:31PM (#27146318)
I'm currently implementing Keycloak for my startup. It's not perfectly documented, but I really like all the things it can do for us and how extensible it is.
Re:Three things to never build yourself: auth, notifications... by znpy on Thursday May 13, 2021 @08:21PM (#27149182)
> It's not perfectly documented

I want to chime in to this too.

If anyone from the Keycloak project is reading: keycloak is awesome, but the documentation is really the most painful part.

The main problem is that it assumes that people installing and/or configuring keycloak already are JBoss/J2EE experts.

Please assume knowledge of GNU/Linux systems, the OAuth/OIDC stuff, LDAP and SAML, but do not assume knowledge of JBoss.

Re:Three things to never build yourself: auth, notifications... by RamblingCTO on Friday May 14, 2021 @06:49AM (#27152856)
They know about that quite well actually. But there's also Keycloak X in the works which is based on Quarkus. It's not mature enough yet but I hope they tackle a lot of the bad things.
Re:Three things to never build yourself: auth, notifications... by joncp on Thursday May 13, 2021 @04:47PM (#27147232)
> not perfectly documented

Understatement of the year!

Re:Three things to never build yourself: auth, notifications... by mooreds on Thursday May 13, 2021 @03:40PM (#27146393)
I'd suggest checking out FusionAuth, but I'm a bit biased :) .

I have heard good and bad things about Keycloak, but I know one thing for sure: it's far better than rolling your own auth.

Good luck with your startup!

Re:Three things to never build yourself: auth, notifications... by outime on Thursday May 13, 2021 @04:44PM (#27147207)
I understand that you want to promote your solution and you have a disclaimer in the previous comment - and that's great. But if you keep insisting then you should IMHO at least provide some reasons on why your solution may be better than e.g. Keycloak and not just posting the name a couple times and see if it sticks.
Re:Three things to never build yourself: auth, notifications... by mooreds on Thursday May 13, 2021 @05:28PM (#27147700)
Fair point. Here's what I'd say if someone was choosing between Keycloak and FusionAuth:

I believe that FusionAuth has a better developer experience. Everything is an API, the docs are regularly updated (though we can always do better). There's an easy way to set up developer environments to a known state (Kickstart) that I don't believe Keycloak has an analog for.

FusionAuth supports limited memory environments. We have folks running in 384MB of memory. From what I've read, Keycloak wants more resources, though Keycloak X is apparently a good alternative. I don't know if Keycloak X has feature parity.

Theming is easier with FusionAuth, more typical auth flows can be themed, and themes can be entirely API managed: https://www.keycloak.org/docs/latest/server_development/#_th... vs https://fusionauth.io/docs/v1/tech/apis/themes/

If you want to run thousands of tenants,, FusionAuth is better. Compare https://keycloak.discourse.group/t/maximum-limit-of-realms/8... vs https://fusionauth.io/blog/2021/03/29/seegno-thousands-tenan...

Both options offer support (Keycloak via the Redhat SSO package), but you can view our pricing without talking to anyone. I wasn't able to find pricing for Redhat SSO (that's usually not a good sign, but maybe someone who has engaged with them can add more, I could be mistaken and it could be super affordable).

FusionAuth has a 100% free as in beer edition with unlimited enterprise or social connections, users, and tenants. (There are certain usage restrictions; you can't package FusionAuth and resell it without a paid license, for example.)

Keycloak has a large community and is 100% open source. Those are definitely strengths that I want to acknowledge.

It's always good to evaluate software as critical as auth (or payments or notifications, for that matter) with a POC simply because everyone's situation is a bit different and it does get embedded in your systems (source: I picked Stripe for a startup and evaluated moving off multiple times to save money but didn't end up doing so in part because of effort and opportunity cost).

Re:Three things to never build yourself: auth, notifications... by bluefirebrand on Thursday May 13, 2021 @06:58PM (#27148545)
You convinced me. I've been eyeballing Keycloak, will definitely give FusionAuth a shot first. :)
Re:Three things to never build yourself: auth, notifications... by mooreds on Thursday May 13, 2021 @07:17PM (#27148713)
Awesome, would love to hear how it goes.
Re:Three things to never build yourself: auth, notifications... by abraae on Thursday May 13, 2021 @05:32PM (#27147749)
I've never checked out your product, but we use Keycloak extensively and I can say it is a great Auth solution and I've used several and even built some (poorly).

The only real downside of Keycloak IMO is the documentation. Because it covers so many bases, and is very extensible, the official doc is enormous. There are a lot of lightweight articles about how to use it, I'd use one of those to get started.

Some great things about it are:

- it's widely used, so you can google your way out of most problems

- it does everything. When someone asks if you have 2FA or support Yubikey - the answer is yes.

- it's very extensible. Great APIs, and you also have access to the underlying database should you really need it (we never have, I'm sure some do).

- it's open source. IMO this is a non-negotiable for an auth system

Re:Three things to never build yourself: auth, notifications... by ozymandias12 on Thursday May 13, 2021 @06:10PM (#27148118)
What other FOSS like Keycloak we have available in 2021? Looking to update my knowledge on options
Re:Three things to never build yourself: auth, notifications... by mooreds on Friday May 14, 2021 @09:24AM (#27154013)
Ones that I've heard of in conversation with customers:

   * IdentityServer (.NET)
   * The ORY suite (hydra, etc)
   * Gluu
I'd say Keycloak is the most common one I hear.

There are about 15 FOSS packages listed here, but you'll need to weed through what is an auth server and what is not: https://en.wikipedia.org/wiki/List_of_single_sign-on_impleme...

Re:Three things to never build yourself: auth, notifications... by abraae on Thursday May 13, 2021 @08:37PM (#27149275)
There is ForgeRock and WSO2 which we have used in the past. Perhaps they have moved on but would not recommend vs Keycloak.
Re:Three things to never build yourself: auth, notifications... by mooreds on Thursday May 13, 2021 @06:39PM (#27148391)
Awesome, appreciate the perspective. A few qs for you:

My understanding is that you ended up writing java code to extend keycloak. Is that wrong?

Is keycloak resource hungry or have I heard wrong? Have you tried keycloak X? Is that better?

Is there a way to configure a dev environment? Is Terraform the preferred IaC solution?

How many realms do you use typically?

Re:Three things to never build yourself: auth, notifications... by abraae on Thursday May 13, 2021 @08:35PM (#27149263)
> My understanding is that you ended up writing java code to extend keycloak. Is that wrong?

Depends what you mean by "extend". For many operations, there are REST APIs, e.g. to create a realm (somewhat equivalent to a tenant in the SaaS world - though see below), it's simply POST /auth/admin/realms. There are also more elaborate extensions such as login listeners that if I remember correctly, you would build in Java, but we don't need those.

> Is keycloak resource hungry or have I heard wrong? Have you tried keycloak X? Is that better?

We haven't found it to be disproportionally resource hungry at all. I'm sure there are scenarios we haven't exercised but resource usage not a problem for us. Not fond of the way vendors throw around allegations like that without hard facts.

> Is there a way to configure a dev environment? Is Terraform the preferred IaC solution?

Depends on your own preferences, we just bring it up in a docker container.

> How many realms do you use typically?

Everyone will skin this cat differently, but for us (SaaS):

- one big realm that most tenants use.

- one admin realm for trusted internal access (i.e. our support team).

- one big realm that candidates use (we are an HR platform)

- one realm per tenant that needs SSO. e.g. if they want to authorise login using their own GSuite account, they get their own realm with their own idp.

As someone else pointed out, having large numbers of realms is a weak point of Keycloak. I look forward to us having enough SSO clients that that becomes a problem for us :)

Re:Three things to never build yourself: auth, notifications... by mooreds on Friday May 14, 2021 @09:19AM (#27153959)
Thanks for sharing your experience.

Always good to hear from someone who's actually used software rather than second or third hand perspectives.

Re:Three things to never build yourself: auth, notifications... by MikeKusold on Thursday May 13, 2021 @03:56PM (#27146603)
> Auth providers cant help you because the passwords are hashed... You need the same algo or you cant authenticate using the data they have.

You absolutely can migrate away from Auth providers. Auth0 (disclaimer: former employer) hashes passwords with Bcrypt, which is most likely the same exact algorithm you would choose. Bcrypt stores salts & rounds as part of the hash making those hashes fairly portable.

Even if you wanted to change algorithms, there are ways to do this so that it is transparent to the user, such as running the plaintext password through a new algorithm after a successful authentication and storing it in a new column.

Re:Three things to never build yourself: auth, notifications... by mypalmike on Thursday May 13, 2021 @06:45PM (#27148438)
He mentioned transparent migration and the problems encountered with it.
Re:Three things to never build yourself: auth, notifications... by BoorishBears on Thursday May 13, 2021 @07:44PM (#27148919)
> Auth providers cant help you because the passwords are hashed... You need the same algo or you cant authenticate using the data they have.

Seeing as you have that it becomes a non-issue

Re:Three things to never build yourself: auth, notifications... by mypalmike on Friday May 14, 2021 @01:23AM (#27151013)
Perhaps I'm incorrectly assuming auth providers don't expose an API for exporting all that data. Such an API would seem to be a fairly attractive attack vector.
Re:Three things to never build yourself: auth, notifications... by systoll on Friday May 14, 2021 @05:11AM (#27152318)
Auth0 and fusionAuth don’t have APIs but will process requests manually.
Re:Three things to never build yourself: auth, notifications... by ocdtrekkie on Thursday May 13, 2021 @02:57PM (#27145889)
It is probably true that outsourcing your authentication to another party is probably bad, you probably should not write your own. So you should likely use a package for your auth code written by someone who focuses heavily on that.
Re:Three things to never build yourself: auth, notifications... by AlchemistCamp on Friday May 14, 2021 @11:47AM (#27155506)
In Elixir-land we're lucky. Jose Valim took his experience from writing Devise (the dominant Ruby gem for auth) and made auth generators for Phoenix apps!

You own the user table, but the auth logic is written by an expert.

Re:Three things to never build yourself: auth, notifications... by patwolf on Thursday May 13, 2021 @03:43PM (#27146430)
I've built auth systems from scratch and used third party auth services. Doing it from scratch always feels reasonable at first when it's just basic username and password, But I start to regret it once a client starts asking for more features. MFA, federation, auditing seem to inevitably become requirements at some point.

If going with a third-party service, my advice would be to make sure you understand how to export the data out of the system, including hashed passwords using a non-proprietary algorithm.

Re:Three things to never build yourself: auth, notifications... by throwaway894345 on Thursday May 13, 2021 @04:34PM (#27147074)
> And the only way off without a mass password reset is a silent migration in the background: migrate the user when they login.. but we all know that will take months and you will never get 100% to login during the migration period.

I would expect that the way to do this sort of migration is to run it until the costs associated with maintaining the migration infrastructure exceed the projected losses due to churn. You don't need to worry much about auth provider pricing because these are typically billed on the basis of monthly-active-users, so even if you have a small number of users who aren't active, they'll hardly show up on your bill. When this pool of unmigrated users is small enough that you can tolerate churning a percentage of them, you can turn off your migration infrastructure and enforce a hard password reset.

That said, I don't know what kind of business has a significant percentage of users who churn because of a one-time password reset. I can't imagine any b2b contracts being canceled because the service provider enforced a password reset. Maybe retail sites are different?

Re:Three things to never build yourself: auth, notifications... by remram on Thursday May 13, 2021 @03:14PM (#27146117)
Making people reset their password is not that big of a deal. I have run into this multiple times, the most recent being amtrak.com. It just told me "you have to reset your password" and I got a link in email like if I had forgotten it. I have also received many "we had a security incident you have to reset your password now" emails in recent years.
Re:Three things to never build yourself: auth, notifications... by sam_lowry_ on Thursday May 13, 2021 @03:40PM (#27146394)
There is a whole line of thought that accounts should be passwordless and accessed via an email reset link as part of normal login procedure.
Re:Three things to never build yourself: auth, notifications... by jedberg on Thursday May 13, 2021 @05:25PM (#27147671)
Yeah I hate that method. It's good in theory but terrible for the user. I go to a website I want to use. I click the magic link. The email takes 10 seconds to show up. In that 10 seconds I find something else to do while I'm waiting. I get distracted and find the magic link in my email 10 minutes later. It's now expired and I have to start over. Or just give up.

With a password, I click the site I want to use, my password manager fills in the password for me, and I click "login" and bam, I'm done.

Re:Three things to never build yourself: auth, notifications... by zimpenfish on Friday May 14, 2021 @04:34AM (#27152090)
> The email takes 10 seconds to show up.

Even longer if you have greylisting turned on, it gets temporarily rejected which means you then have to wait N minutes before it gets accepted (assuming they retry sensibly and don't just spam retries every 2 minutes and get fail2ban'd.)

By which time it might well have timed out anyway...

Re:Three things to never build yourself: auth, notifications... by OJFord on Thursday May 13, 2021 @08:12PM (#27149127)
A faulty line that's miserable UX and barely better security, but sure, a line.
Re:Three things to never build yourself: auth, notifications... by slavboj on Thursday May 13, 2021 @04:02PM (#27146673)
Which is great until you lose access to your email.
Re:Three things to never build yourself: auth, notifications... by em-bee on Thursday May 13, 2021 @07:57PM (#27149023)
if you loose access to your email, you may just be out of luck. a good service will not allow you to change your registered email address without verifying that you own the old one
Re:Three things to never build yourself: auth, notifications... by yawaramin on Thursday May 13, 2021 @09:40PM (#27149667)
Not in my experience. Every account I can think of allows me to change my email address without verifying the old one.
Re:Three things to never build yourself: auth, notifications... by dstick on Friday May 14, 2021 @01:30AM (#27151046)
And how would you even login to your email using that method :)
Re:Three things to never build yourself: auth, notifications... by noAnswer on Thursday May 13, 2021 @03:43PM (#27146422)
You sure it wasn't phishing. SCNR
Re:Three things to never build yourself: auth, notifications... by remram on Thursday May 13, 2021 @03:46PM (#27146473)
Yes
Re:Three things to never build yourself: auth, notifications... by noAnswer on Thursday May 13, 2021 @04:41PM (#27147170)
Every phishing mail I've ever got talked about something something security click this link pl0x. OP is right in the sense that not everyone will follow (in a given time frame) and "You will incur damage".

...but the same is true if you would have a leak. So whatever I guess.

Re:Three things to never build yourself: auth, notifications... by chaostheory on Thursday May 13, 2021 @03:03PM (#27145985)
You can do both. Just use an open source project for auth instead of reinventing a commodity wheel.
Re:Three things to never build yourself: auth, notifications... by rdevsrex on Thursday May 13, 2021 @06:24PM (#27148260)
I am on the side of not using one of these Auth companies, but if you are learning or just want to make a proof of concept fast, it definitely helps to have that taken care of for you.
Re:Three things to never build yourself: auth, notifications... by AlexSW on Thursday May 13, 2021 @03:00PM (#27145938)
Using the same authentication algorithm doesn't seem like a particularly big price to pay, assuming they started with a sensible one. And there's nothing stopping one from making it support the old style but add a more up-to-date algorithm for new password sets, either.
Re:Three things to never build yourself: auth, notifications... by lwhi on Thursday May 13, 2021 @06:27PM (#27148294)
Why not build in abstraction?

If you have a middleware that lets you swap providers, you can start off with a ready made solution and switch if necessary.

Obviously, this still means you need to maintain control over your data; but that's surely something a startup will do in any scenario, right?

Re:Three things to never build yourself: auth, notifications... by unethical_ban on Thursday May 13, 2021 @03:18PM (#27146167)
It's one thing to host your own/maintain your own auth database, but there is a definite benefit of using a tool like Okta SSO to link your authn to other services, if that's your business.
Re:Three things to never build yourself: auth, notifications... by void_mint on Thursday May 13, 2021 @03:00PM (#27145936)
> Never outsource Auth. Maintain control over user accounts.

This is some of the worst advice I've ever seen on HN. Don't take on risk you don't understand and cannot afford to mitigate. Don't be the next Equifax.

Re:Three things to never build yourself: auth, notifications... by debaserab2 on Thursday May 13, 2021 @03:21PM (#27146206)
This is literally the Auth0 first contact sales pitch designed precisely to scare you out of even trying to assess the risk of building it yourself.

The reality is, though, it's never been easier than it is today to build secure auth - yes, it's still hard to do it right - but less hard than it ever has been before. So many security features are now a checkbox on a cloud provider's web interface that would have been a manual implementation of the underlying protocol a decade ago. So many languages have matured battle-tested OS libraries for handling the especially sensitive parts like crypto.

This notion that it is a "no-brainer" decision to happily trade your customer database and a % of revenue to remove the burden of stewardship seems crazy to me.

Re:Three things to never build yourself: auth, notifications... by deergomoo on Thursday May 13, 2021 @04:28PM (#27146995)
Not to mention there’s a whole lot of middle ground between writing your own auth logic and using a hosted service. Any reasonably popular web-oriented language has plenty of fully featured, high quality libraries you can often just drop in.

Hell, we use Laravel at work, which includes pretty robust auth features out of the box. It feels like such table stakes stuff for a web framework that I find the idea of paying for a third-party cloud service absolutely bananas.

It also includes pretty solid notification and payment solutions too, though these usually plug into services like SNS and Stripe and don’t really fit the “self hosted” bill.

Re:Three things to never build yourself: auth, notifications... by beardbandit on Thursday May 13, 2021 @05:29PM (#27147704)
I think that's where the confusion lies. Are people suggesting someone to write their own auth from the ground up, or write auth in coordination with their stack's auth library of choice?
Re:Three things to never build yourself: auth, notifications... by joshmanders on Friday May 14, 2021 @10:43AM (#27154842)
It appears to me the assumption these people / articles make is that nobody is using existing hardened production ready libraries, but hand writing everything from the ground up for their todo app.

Because otherwise their message falls flat on its face.

Re:Three things to never build yourself: auth, notifications... by bob1029 on Thursday May 13, 2021 @08:31PM (#27149246)
> So many languages have matured battle-tested OS libraries for handling the especially sensitive parts like crypto.

We use CSPRNG/SHA256/SHA512/AES/3DES/RSA primitives in .NET without any trouble. Microsoft made it pretty difficult to fuck things up as long as you don't sprinkle Math.Random in with your session token logic like a jackass.

Re:Three things to never build yourself: auth, notifications... by colinclerk on Thursday May 13, 2021 @06:51PM (#27148484)
> but less hard than it ever has been before

I have a very vested interest in this (founder Clerk.dev) - but the exact opposite experience is what led us to start Clerk.

Auth was easy when it was just email verification and choosing the right hashing algorithm. I used to pull Devise off the shelf and get it going in 30 minutes.

But these days, the simple solution is far from complete. I grew most frustrated trying to setup the rest...

- Single sign-on / Oauth with proper de-duping so users can always sign in regardless of how they signed up

- 2fa so users can better secure their accounts

- Integrations with a leaked password corpus (haveibeenpwned) to prevent credential stuffing attacks

- Active device tracking and remote session revocation

You can launch without these things, but it's definitely impacting your overall security and the conversion rates through your sign up and sign in flows.

Re:Three things to never build yourself: auth, notifications... by zzt123 on Thursday May 13, 2021 @09:09PM (#27149464)
I found these features quite simple to implement. What gave me a headache was advanced anomaly detection (both from the per-account and per-requester perspectives) and handling. For me, there is no bottom of the well on those things, and they are the killer features of auth as a service.
Re:Three things to never build yourself: auth, notifications... by Raed667 on Thursday May 13, 2021 @03:05PM (#27146010)
It is really not difficult to use BCrypt or Argon2 with your backend of choice.

Proper password and session management have been made accessible for many years if you use any "modern" backend.

Re:Three things to never build yourself: auth, notifications... by bhaney on Thursday May 13, 2021 @03:34PM (#27146336)
> It is really not difficult to use BCrypt

Something I once saw in production:

An otherwise normal usage of bcrypt, that "prehashed" the password with sha512 before passing the resulting hash to bcrypt. This is conceptually reasonable (although not very useful) for reasons I don't think are worth going into, but had two critical problems.

1. It technically broke bcrypt's side-channel protection against timing attacks (bcrypt runs in constant time, while sha512 does not).

2. The much worse issue was that the binary hash was being passed to bcrypt. If bcrypt encounters a null byte in the input, it considers that to be the end of the input and ignores everything after, c-string style. Every byte of the binary hash had a 1/256 chance of being a null byte, which means 1/256 passwords result in a hash with the first byte being null, which means bcrypt will accept any of them as equivalent to the others. You could login to 0.4% of accounts by guessing ~256 completely random passwords (and a larger number of passwords were similarly but less extremely weakened)

You can say "well that's their fault for mucking with the input to bcrypt" but I bet most people would believe that kind of operation was safe before it's explained to them why it's not. It's very easy to accidentally destroy the security of a crypto scheme without knowing it, and thinking that what you're doing is perfectly run of the mill and safe.

Re:Three things to never build yourself: auth, notifications... by deckard1 on Thursday May 13, 2021 @08:27PM (#27149223)
What's been interesting to me is that during tech interviews, we eagerly have applicants roll their own sorting, or searching, or caching. But you never have questions about crypto or auth. Why one and not the other? Are both not critical to get right?

And then I'm reminded of the bug that was hidden in plain sight for 20 years in Programming Pearls[1] in their implementation of a binary search. This same algorithm was copied in Java and elsewhere, near verbatim. So, yeah, maybe don't roll your own searching either. The experts have enough difficulty.

Frankly, I don't trust most programmers to get anything right. People toss around "battle-tested" libraries and we all just take it for granted that that's what they are. But I recently found out one incredibly popular package for one incredibly popular language is doing something fairly dumb. Not insecure (that I can tell). Just simply unnecessary. They are signing session cookies. For reasons I could not fathom. Signing doesn't prevent cookie theft. It's just another layer that someone thought would add security over just sending a random string (hopefully your system/language's random generator is actually random). And that's how a lot of these mistakes happen. Let's add sha512 on top of our crypto. Because more = better, right?

Speaking of random, there was another popular package out there for generating UUIDs that has a github issue where someone discovered the package was generating collisions. Yikes.

[1] https://ai.googleblog.com/2006/06/extra-extra-read-all-about...

Re:Three things to never build yourself: auth, notifications... by yoyonamite on Thursday May 13, 2021 @11:57PM (#27150526)
Isn't signing the session cookie to prevent cookie tampering? You can send a random string, but you would need to persist the random string somewhere in order to verify against it later
Re:Three things to never build yourself: auth, notifications... by DougN7 on Friday May 14, 2021 @10:11AM (#27154526)
The cookie value has to be stored in some sort of map\dictionary that links to the session data. If the cookie value is a random string, you don’t need to store any more data than you would with a hashed cookie value. Or maybe I’m misunderstanding your point?
Re:Three things to never build yourself: auth, notifications... by yoyonamite on Friday May 14, 2021 @10:52PM (#27161875)
ah, okay. I think I misunderstood. I was thinking about the case where the data is stored in the cookie itself (i.e. an encrypted cookie), and you would need a way to verify that the contents weren't altered. If it's storing a session id, then there isn't a reason to also sign it. Sounds like they conflated the two approaches.
Re:Three things to never build yourself: auth, notifications... by arcbyte on Thursday May 13, 2021 @03:41PM (#27146411)
Thank you for sharing that experience. It was a very interesting read.

However, lest anyone get the wrong opinion, password hashing is a very simple, straightforward, solved problem and has been for years.

One person doing something monumentally stupid doesn't make Auth some kind of cryptic minefield.

Re:Three things to never build yourself: auth, notifications... by bhaney on Thursday May 13, 2021 @03:59PM (#27146636)
My point is precisely that it wasn't "monumentally stupid," but rather a pretty reasonable decision given what the average person would expect bcrypt to provide functionally. The behavior I described is an unexpected landmine that people using bcrypt need to be aware of. There are likely others, though probably not enough that I would describe it as a minefield.

I would wager that most people reading this, if earnestly asked by a coworker "do you think it's fine for me to hash a password before passing it to bcrypt? I want to be able to support passwords over 72 characters and bcrypt truncates its input." would answer something along the lines of "I don't see how it could hurt" rather than "that's dangerous because a binary hash would result in a large portion of the passwords being hashed as an empty string"

The engineers that originally implemented and reviewed this were not idiots, they just weren't security experts.

Re:Three things to never build yourself: auth, notifications... by nicoburns on Thursday May 13, 2021 @07:02PM (#27148575)
My answer would definitely be: I don't know, but why bother. We know bcrypt by itself works. We don't know whether it works combined with another hash, and it's extra code we need to maintain.
Re:Three things to never build yourself: auth, notifications... by capableweb on Thursday May 13, 2021 @03:47PM (#27146494)
> Stop trying to make something sound difficult that isn't. Password hashing is a very simple, straightforward, solved problem and has been for years.

Try asking the following question on Twitter:

"While passing binary data, which example is safer for storing passwords?

[ ] $password | sha256 | bcrypt

[ ] $password | bcrypt"

What do you think the average programmer would say? Most would probably say they are either equal, or the first one, without knowing this specific thing, because most people don't implement their own password-hashing, they use library/framework provided ways that has been established as best practice already.

But, can't blame them really, the difference is marginal and innocent on the surface, but once you understand the implementation, you'll see the holes.

Re:Three things to never build yourself: auth, notifications... by whakim on Thursday May 13, 2021 @06:12PM (#27148132)
I think the question isn't particularly relevant because many programmers are just using bcrypt in a simple way that's very well documented. I think it's reasonable to expect people to know that "auth is dangerous, don't just do your own special thing and assume it'll be fine." If you want to do something that diverges from the simple case, then please don't try to roll your own auth.
Re:Three things to never build yourself: auth, notifications... by wieghant on Thursday May 13, 2021 @06:02PM (#27148048)
It's monumentally stupid to think auth is easy. Yes there are standard cookbooks and checklists out there. The hubris to think that auth fails due to a crypto scheme choice is why average programmers consistently fail at it.

The yearly report of leaks in Fortune 500 companies should be proof enough of this.

EDIT: To elaborate. Crypto scheme is only one tiny facet of a successful authentication solution. Where do you store the hash? What language and stack are you using? What is the maturity of libraries available to you? What protocols? And many more seemingly tiny decisions. All it takes is a lazy developer that imports an insecure transient dependency or snoozes on a CVE.

Re:Three things to never build yourself: auth, notifications... by kelnos on Thursday May 13, 2021 @06:17PM (#27148191)
> You can say "well that's their fault for mucking with the input to bcrypt" but I bet most people would believe that kind of operation was safe before it's explained to them why it's not.

What makes you think this foolish developer would not do the exact same thing before sending the data to an externally hosted auth service?

Re:Three things to never build yourself: auth, notifications... by GormanFletcher on Thursday May 13, 2021 @06:45PM (#27148441)
The external auth service's API would receive textual input (expecting a string read from a textbox), not binary. A hash that included null bytes would output those in hex as ASCII zeroes, which wouldn't cause the same problem when the external service received the value.
Re:Three things to never build yourself: auth, notifications... by jlokier on Thursday May 13, 2021 @08:11PM (#27149119)
And that is, in fact, how you should perform a hash before bcrypt as well.

bcrypt accepts text input, not binary.

So if you use a pre-hash, you pass the hex or base64 output from the hash to bcrypt.

Re:Three things to never build yourself: auth, notifications... by jlokier on Thursday May 13, 2021 @07:53PM (#27148980)
It's not that non-standard. You are describing the method Dropbox wrote a post about some years ago:

https://dropbox.tech/security/how-dropbox-securely-stores-yo...

> First, the plaintext password is transformed into a hash value using SHA512. This addresses two particular issues with bcrypt. Some implementations of bcrypt truncate the input to 72 bytes, which reduces the entropy of the passwords. Other implementations don’t truncate the input and are therefore vulnerable to DoS attacks because they allow the input of arbitrarily long passwords. By applying SHA, we can quickly convert really long passwords into a fixed length 512 bit value, solving both problems.

> Next, this SHA512 hash is hashed again using bcrypt with a cost of 10, and a unique, per-user salt. Unlike cryptographic hash functions like SHA, bcrypt is designed to be slow and hard to speed up via custom hardware and GPUs. A work factor of 10 translates into roughly 100ms for all these steps on our servers.

> Finally, the resulting bcrypt hash is encrypted with AES256 using a secret key (common to all hashes) that we refer to as a pepper. The pepper is a defense in depth measure. The pepper value is stored separately in a manner that makes it difficult to discover by an attacker (i.e. not in a database table). As a result, if only the password storage is compromised, the password hashes are encrypted and of no use to an attacker.

Re:Three things to never build yourself: auth, notifications... by jlokier on Thursday May 13, 2021 @08:03PM (#27149070)
Your point 1 seems wrong. SHA-512 is constant time for any reasonable password length and any reasonable implementation. It hashes 1024-bit blocks in constant time, as it only uses 64-bit word operations such as add, shift, xor etc in a fixed order with fixed constants. There are no input data-dependent lookups, or other variable-time operations.

If you are considering the string copy that happens when the unhashed password is copied into the block to be variable time, probably you shouldn't count that against SHA-512 because there will be variable-length string operations before bcrypt starts its hashing too. Not to mention parsing it out of HTTP parameters or reading it from a GUI control. (If you really care about timing observations, perhaps you'd pre-hash the password on the client so what is transmitted is fixed-length).

Point 2 is of course a real problem. Though to be honest I've always regarded the NUL check and (sometimes, implementation-dependent) maximum length as unnecessary, arbitrary flaws in bcrypt - so bcrypt gets the blame. On grounds of purity and doing the right thing, I refuse to use raw bcrypt, and in fact I use: SHA-512 -> Base64 -> bcrypt when password hashing.

Does that make me wrong? Only if Dropbox is wrong (I hope they just forgot to mention Base64 in their old security article.)

Re:Three things to never build yourself: auth, notifications... by bhaney on Thursday May 13, 2021 @10:37PM (#27150063)
> Your point 1 seems wrong. SHA-512 is constant time for any reasonable password length and any reasonable implementation.

I'm aware of this, and it's why there's a "technically" in my original point. Of course in practice it makes no difference, and I consider the better use of bcrypt's input space when prehashing to outweigh leaking a pretty useless amount of side-channel information for extraordinarily long passwords.

Though as a follow up anecdote, one of the engineers there had set a 300kB password to test the prehashing implementation, and just continued to use it (via password manager). He was potentially leaking a bit of timing information. I'm not even sure if a password that long made a timing difference that was detectable through network jitter, but if it did and some hypothetical attacker was able to learn that his password was hundreds of kilobytes long, well... good luck.

> in fact I use: SHA-512 -> Base64 -> bcrypt when password hashing. Does that make me wrong?

No, using a base64 representation of the sha hash makes your scheme perfectly reasonable. Also note that the base64 representation of sha512 is a bit longer than the typical bcrypt input length, so you're shrinking the collision space somewhat by truncating your sha hash. Certainly not enough that it would matter at all, just a point I find interesting. Hypothetically, a binary representation with a pass that removed or replaced NUL bytes would preserve more entropy, but we're well past the point where it matters and would be playing with fire to consider that complexity.

Re:Three things to never build yourself: auth, notifications... by jlokier on Friday May 14, 2021 @02:36AM (#27151405)
256 bits is enough collision resistance, so I don't mind truncating SHA-512, even down to 256 bits.

If you find collision space reduction interesting, then you might find it even more interesting that truncating SHA-512 makes it more secure not less.

This (and the higher rounds safety margin) is why I choose truncated SHA-512 over SHA-256 for this sort of application, even though the number of output bits is the same:

Check out the red boxes on https://en.wikipedia.org/wiki/Template:Comparison_of_SHA_fun...

Re:Three things to never build yourself: auth, notifications... by city41 on Thursday May 13, 2021 @03:12PM (#27146100)
It's true the happy path and common error cases are easy to account for. But it just takes one overlooked bug or vulnerability either in your code or a library's code to send it all crashing down.
Re:Three things to never build yourself: auth, notifications... by arcbyte on Thursday May 13, 2021 @03:47PM (#27146484)
This is true across the board. One tiny crack in a bridge might mean it will collapse. That doesn't mean we should stop building bridges.
Re:Three things to never build yourself: auth, notifications... by void_mint on Thursday May 13, 2021 @05:26PM (#27147684)
Sure, but it certainly means we should leave bridge building to those who are experts in that field.
Re:Three things to never build yourself: auth, notifications... by void_mint on Thursday May 13, 2021 @03:07PM (#27146034)
> Its really not difficult

Good luck to you!

Re:Three things to never build yourself: auth, notifications... by remram on Thursday May 13, 2021 @03:16PM (#27146139)
I don't think the main problem with Equifax was the Auth info they lost. It was their own business data, e.g. social security numbers etc, which wouldn't have been outsourced to their Auth provider anyway.
Re:Three things to never build yourself: auth, notifications... by troygoode on Thursday May 13, 2021 @03:03PM (#27145979)
100%. I'm old enough that when I started my career we were still storing credit card numbers on our servers (and many companies were unfortunately doing so in the raw...). PCI compliance luckily knocked some sense into the industry. Crazy to me that some people don't realize that PII and secrets like passwords are basically in the same category now.
Re:Three things to never build yourself: auth, notifications... by guiomie on Thursday May 13, 2021 @03:08PM (#27146041)
But he's arguments are pretty sound to me. Do you have any counter-arguments than a generic statement?
Re:Three things to never build yourself: auth, notifications... by jayd16 on Thursday May 13, 2021 @03:28PM (#27146283)
I guess the question is what's more likely, Facebook, Google or Apple leaving the oauth game or a bug in an internal solution.
Re:Three things to never build yourself: auth, notifications... by capableweb on Thursday May 13, 2021 @03:43PM (#27146428)
You're missing the original point. rgbrenner is talking about auth solutions like Auth0 where users can use username + password to sign up/login, and when you eventually are gonna have to leave (which, if your business is successful, you eventually will), you'll need to reset passwords one way or another.

Of course, if you only use third-party authentication for your service, it doesn't really matter what's in-between there, you can work around it.

Re:Three things to never build yourself: auth, notifications... by bryanrasmussen on Thursday May 13, 2021 @03:41PM (#27146410)
what's more likely - you being able to talk to Facebook, Google, or Apple to let your app/site use their authorization solution once their algorithm has decided to ban you, or you fixing your bug.
Re:Three things to never build yourself: auth, notifications... by habibur on Thursday May 13, 2021 @03:50PM (#27146528)
That they will ban you for one reason or other has a very high possibility of occurring before you go out of business.
Re:Three things to never build yourself: auth, notifications... by jayd16 on Thursday May 13, 2021 @03:59PM (#27146635)
You and I have different definitions of very high possibility.
Re:Three things to never build yourself: auth, notifications... by withinboredom on Thursday May 13, 2021 @06:42PM (#27148413)
I had an app get banned for copyrighted content by Google because there was a movie poster in one of the backgrounds of the screenshots (camera type app in 2013). It will happen, probably for something ridiculous. In every job I’ve worked at, it had happened or they’d been threatened to be banned, at least once.
Re:Three things to never build yourself: auth, notifications... by dvdkon on Thursday May 13, 2021 @03:07PM (#27146032)
In what scenario do you need to have personal info associated with accounts and don't need to have full access to it? I see no user privacy benefits to outsourcing auth, unless all you need is to do is to verify someone's a real person.
Re:Three things to never build yourself: auth, notifications... by justinclift on Thursday May 13, 2021 @09:09PM (#27149462)
Well, we implemented Auth using Auth0. The experience wasn't terrible, but not fantastic either. Probably best described as "ok".

However, now they've been bought by Okta, which has a pretty bad reputation.

So, I guess we'll get to find out eh?