News for hackers. Stuff that matters.
Re:How to Safely Store Your Users' Passwords in 2016 by rcconf on Wednesday February 17, 2016 @11:59AM (#11119239)
If you're using node.js and you use these hashing methods, your entire server is going to pause for 0.5 seconds on a login because it runs on a single thread. Goodbye to all of your server performance.

You can create a worker system, or use a child process to solve this problem, but most of these articles never mention it

Re:How to Safely Store Your Users' Passwords in 2016 by lukev on Wednesday February 17, 2016 @12:02PM (#11119267)
I think this says more about node.js than it does about the proper way to secure a password.
Re:How to Safely Store Your Users' Passwords in 2016 by ARussell on Wednesday February 17, 2016 @12:15PM (#11119369)
Wasn't Node's big draw early on (aside from the fact that it's JavaScript) the fact that everything is supposed to be asynchronous? I'm actually surprised this is a problem.
Re:How to Safely Store Your Users' Passwords in 2016 by sotojuan on Wednesday February 17, 2016 @12:30PM (#11119503)
Everything is asynchronous but the linked article uses the synchronous versions of the functions for some reason... async versions exist and are recommended[1]

[1] https://github.com/ncb000gt/node.bcrypt.js#async-recommended

Re:How to Safely Store Your Users' Passwords in 2016 by zwily on Wednesday February 17, 2016 @12:38PM (#11119576)
Do the async methods actually execute on a thread pool though? Or do they use enough async methods internally to periodically release the main thread enough to keep it responsive?

From a quick glance at the source, the answer to the first is no.

Re:How to Safely Store Your Users' Passwords in 2016 by phpnode on Wednesday February 17, 2016 @12:47PM (#11119648)
This one is truly async, it uses a libuv managed thread pool.
Re:How to Safely Store Your Users' Passwords in 2016 by zwily on Wednesday February 17, 2016 @01:03PM (#11119812)
Yep you're right - disregard what I said above. :)
Re:How to Safely Store Your Users' Passwords in 2016 by mobiuscog on Wednesday February 17, 2016 @12:25PM (#11119451)
asynchronous doesn't magically make CPU-intensive tasks faster.
Re:How to Safely Store Your Users' Passwords in 2016 by corobo on Wednesday February 17, 2016 @01:56PM (#11120257)
It does mean other tasks (e.g. serving pages to visitors) can still be run at the same time as the CPU-intensive task though, like most languages do when it comes to hashing passwords and logging people in
Re:How to Safely Store Your Users' Passwords in 2016 by kornish on Wednesday February 17, 2016 @01:56PM (#11120256)
Correct, but it sure does stop your entire single-threaded process from blocking to the detriment of all other requests.
Re:How to Safely Store Your Users' Passwords in 2016 by EGreg on Wednesday February 17, 2016 @02:49PM (#11120685)
It says both. The hashing is computationally expensive and Node runs in a single process (if we ignore workers). They could have made an implementation that yields and resumes after several ms. or you can spawn a worker and send it jobs.
Re:How to Safely Store Your Users' Passwords in 2016 by herbst on Wednesday February 17, 2016 @02:14PM (#11120383)
Wouldnt this happen with pretty much anything that is not threaded by default? Clearly with PHP you give a fuck, but i assume its not different with Ruby, Python, Go, ASP or anything else. You just usually use them threaded.
Re:How to Safely Store Your Users' Passwords in 2016 by Joeri on Wednesday February 17, 2016 @02:29PM (#11120515)
PHP is usually deployed in a FastCGI multiprocess setup, so the server will keep handling requests on the other processes while the hashing process is blocked.

I wonder whether threading really saves you, given that there are only so many cores in a system and password hashing is CPU heavy. Naively it seems a DoS would involve sending as many parallel requests as there are cores, which is not a lot and can easily be done from a single machine.

Re:How to Safely Store Your Users' Passwords in 2016 by sarciszewski on Wednesday February 17, 2016 @02:32PM (#11120537)
The blog post that HN is reading is served by PHP-FPM + nginx, without any extra special features to handle the load of an unexpected "oh hey we made it to the front page of HN".

It's also hosted on a relatively cheap VPS.

Re:How to Safely Store Your Users' Passwords in 2016 by seanp2k2 on Thursday February 18, 2016 @02:26AM (#11124241)
Considering the other article from HN today about Stack Overflow being able to handle their top-100 global Alexa rank traffic with one physical web front end, I'm impressed but not that impressed. PHP has been popular for a long time and lots of smart people have figured out how to make it pretty quick.

For things like blog posts, I'm sad that Movable Type fell out of favor. The pattern of using dynamic server pages to edit blog posts and generate static files for your viewers just makes so much sense to me. Then again, these days we can host our single-page JS front-ends on S3 + CloudFront and hook them up to API gateway and Lambda / Beanstalk talking to RDS and "not have any servers" :)

Re:How to Safely Store Your Users' Passwords in 2016 by herbst on Wednesday February 17, 2016 @05:16PM (#11121918)
I know thats what i ment with usually you give a fuck, i dont know any way you could run PHP single threaded on a server (i mean there sure is). But its something common you learn when you programm in the other languages i mentioned.

I dont think it could get a real issue in a real environment, except someone really wants to fuck with you. But the some fail2ban on to fast requests should fix this easily as the hashes dont actually take that long.

Re:How to Safely Store Your Users' Passwords in 2016 by girvo on Wednesday February 17, 2016 @07:31PM (#11122760)
> i dont know any way you could run PHP single threaded on a server

Using `php -S 0.0.0.0:80 index.php` would do it!

Re:How to Safely Store Your Users' Passwords in 2016 by seanp2k2 on Thursday February 18, 2016 @02:19AM (#11124211)
Even with mod_php you get 1 per fork with the prefork mpm, so this wouldn't even stop some Apache 2.2 box with php4 configured 10 years ago from accepting new connections.
Re:How to Safely Store Your Users' Passwords in 2016 by marcosdumay on Wednesday February 17, 2016 @02:35PM (#11120563)
Yes. That's why nearly every web framework is threaded by default. That includes everything you'll find in Ruby, Python, Go, or ASP.

Not serializing IO, but them stopping every worker just because one of them has some hard work to do is not a sane working model for web backends.

Re:How to Safely Store Your Users' Passwords in 2016 by jrochkind1 on Thursday February 18, 2016 @08:15AM (#11125468)
It's pretty new that Rails is arguably 'threaded by default', and many/most typical deploy setups for Rails still don't run with multi-threaded request dispatch.

But yes, I agree with you that that is why every web app _should_ be threaded.

Re:How to Safely Store Your Users' Passwords in 2016 by EGreg on Wednesday February 17, 2016 @02:50PM (#11120694)
That's why you spawn worker processes and servers. Evented IO is way faster than threads as NGinX and Node have shown.
Re:How to Safely Store Your Users' Passwords in 2016 by StavrosK on Wednesday February 17, 2016 @12:14PM (#11119358)
It definitely does, and I think that's the GP's point.
Re:How to Safely Store Your Users' Passwords in 2016 by phillipburch on Wednesday February 17, 2016 @12:26PM (#11119466)
Or you could just use the async versions.... https://www.npmjs.com/package/bcrypt-nodejs
Re:How to Safely Store Your Users' Passwords in 2016 by zwily on Wednesday February 17, 2016 @12:30PM (#11119500)
Does that library do the calculations in a thread pool, or is it just async on the main thread? If the latter (which seems mostly likely), then it won't matter.
Re:How to Safely Store Your Users' Passwords in 2016 by warfangle on Wednesday February 17, 2016 @12:57PM (#11119738)
It looks like that one is pure JS, using native node crypt functionality for randomness.

The one recommended in the article[0] actually includes a blowfish C++ binding, with both synchronous and asynchronous methods for comparing and hashing. That binding uses NAN[1] to queue AsyncWorkers. NAN uses libuv[2] behind the scenes to launch a thread[3].

0. https://www.npmjs.com/package/bcrypt

1. https://github.com/nodejs/nan

2. https://github.com/libuv/libuv

3. https://blog.scottfrees.com/building-an-asynchronous-c-addon...

Re:How to Safely Store Your Users' Passwords in 2016 by phpnode on Wednesday February 17, 2016 @12:44PM (#11119623)
It does it on the main thread, pseudo-async, so I agree with you, you should not use this library. Look for a native module instead.
Re:How to Safely Store Your Users' Passwords in 2016 by lazyjones on Wednesday February 17, 2016 @06:14PM (#11122338)
> You can create a worker system, or use a child process to solve this problem, but most of these articles never mention it

Or you can do the bcrypt() inside your (PostgreSQL) database and add an extra layer of security by not directly exposing the hash (or even the whole password table) to the web server process (i.e. write a password check SQL function and allow only calling it, no direct table/column access).

Re:How to Safely Store Your Users' Passwords in 2016 by NickNameNick on Wednesday February 17, 2016 @09:46PM (#11123313)
Congratulations, now there are plaintext passwords in your server logs...

I did exactly what you are suggesting on a project some time ago - deferred to the database to do the password hashing and comparison to the stored hash. Unfortunately, the server query logs contained the query parameters. So did some of the database logs when running at elevated log levels. We quickly decided that was unacceptable, and moved the hashing process into the web server.

Re:How to Safely Store Your Users' Passwords in 2016 by swang on Wednesday February 17, 2016 @10:41PM (#11123558)
I don't see how moving to the web server would prevent that if you were logging passed req body or query parameters since they would be posted in plaintext (hopefully) over a https connection.
Re:How to Safely Store Your Users' Passwords in 2016 by minitech on Wednesday February 17, 2016 @11:19PM (#11123696)
“query parameters” here are the parameters passed to PostgreSQL. That is, "SELECT * FROM users WHERE password_hash = get_hash('P4ssw0rd')" is being logged, not "?password=P4ssw0rd".
Re:How to Safely Store Your Users' Passwords in 2016 by NickNameNick on Thursday February 18, 2016 @06:27AM (#11125055)
Exactly so.

The webserver framework I was using at the time logged all its queries to the database at the normal log level. It couldn't log an actual query string because we used prepared statements, but it reconstructed the query and substituted the parameters in.

Enormously helpful for debugging an issue, when you can just copy and paste a query out of the serverlogs. Although I would probably have preferred that it not do that at the normal log level.

Curiously, it never logged the http request string/parameters. When I wanted that I had to add my own code to the request handler.

Re:How to Safely Store Your Users' Passwords in 2016 by theIV on Wednesday February 17, 2016 @11:12PM (#11123678)
I'm not sure but I'm assuming this has more to do with Postgres' WAL than it does filtering logs. I've never used this side of Postgres though, so just a guess.
Re:How to Safely Store Your Users' Passwords in 2016 by neals on Wednesday February 17, 2016 @02:53PM (#11120715)
I find that using the original bcrypt node module is hard to build consistently, I often have trouble getting it built on various systems. I switched to bcryptJS which is a drop-in JS implementation.

Anybody here that knows if any of these is a valid replacement? https://nodejs.org/api/crypto.html

Re:How to Safely Store Your Users' Passwords in 2016 by warfangle on Wednesday February 17, 2016 @01:06PM (#11119842)
Incorrect; the first hashing method recommended uses a native CPP binding which launches a thread to execute both hashing and comparing.

Unfortunately, the example used for the bcrypt node module is the async form of hashing. That library exports both sync and async forms of hash/compare.

Re:How to Safely Store Your Users' Passwords in 2016 by abjorn on Wednesday February 17, 2016 @12:25PM (#11119457)
The particular module being used in the article has async versions of those methods. He uses the synchronous versions in the example presumably for clarity/brevity.
Re:How to Safely Store Your Users' Passwords in 2016 by dfischer on Wednesday February 17, 2016 @12:35PM (#11119548)
Have any examples of how to properly handle it with node? Isn't it just the typical callback pattern?