157 points · by ColinWright · 14y ago · 121 comments
If someone attempts a password reset on foo@example.com, and there is no record in the DB for foo@example.com, immediately tell them so.
Why?
1) While this does "leak" the fact of foo@example.com not being in the DB (and, by consequence, can be used to verify whether any email is in the DB), naive implementations of the best practice will also leak that via a side channel. If you would not immediately greenlight $20k to have a security consultant spend one week auditing this feature extensively to avoid the timing attack, a) your app is not important enough for this level of security and b) this buys you no real security, just the illusion of it.
1.5) This is totally security theatre if you have a registration process which checks for provided emails already being the in the DB, for example for telling people "That email is taken." Different route through the maze but same cheese at the end.
2) You can already spearphish people for their accounts on example.org . Start with an email list of people. Spearphish for their accounts irrespective of whether they have them or not. Collect wins since losses cost your botnet nothing at the margin.
3) MOST IMPORTANTLY: you're buying yourself six years of frustrated emails from customers which had 90% totally automatically discoverable solutions if you do this the "right" way. I'm speaking from experience. Many of your customers have multiple emails they habitually use. If you do the best practice, every time they misremember which one they signed up with, you get a support email. This will be your #1 cause of support emails and the cost for dealing with them is astronomically higher than the minimal marginal gain in security for your users.
Edit: Omnibus response for people doubting that a side channel attack is possible:
The attacker wins with microsecond precision over the open Internet and nanosecond precision over the local network, which is plausibly achievable on all of the cloud providers than HNers like to host their apps at. Microsecond precision is enough to discriminate between "record in DB" and "record not in DB" on many plausible application architectures, even if your HTML/headers returned are exactly identical for the two cases (and they frequently won't be out of the box).
For example, the relevant code for Bingo Card Creator includes the line
user = User.find_by_username(params[:email])
This line takes approximately 30x longer to execute if it finds a user in the DB versus not finding a user. Why? ActiveRecord. You could, if you had a mind to, trivially discriminate between the two cases in under a week over the open Internet. If you really wanted to ruin my day, you could get a prepaid Visa card and get a VPS from Rackspace on the same intranet, then discriminate between the two responses in under an hour, again without tripping anything.
Some folks think there are trivial ways to defeat timing attacks. You are either mistaken or you have a very different view of the word "trivial" than I do.
However, the original article did raise a point - there are some contexts in which leaking membership might be especially embarrassing. I don't think any of my coworkers would use timing attacks to determine if my email address is in the database of someembarrassingpornsite.com, but typing in my email address and seeing if you get an error is within the intuitive grasp of many preschoolers. Perhaps the guidance should be that for 90% of sites you don't need to worry about disclosing membership, for 9% you should consider a naive implementation of the best practice, and 1% should get in a security consultant.
Have you considered doing what EDW did and compiling a book of your HN replies, expanded by further insights gained while doing so? Would you have time? I'm sure many would find it valuable.
int MAX_RESPONSE_TIME; start = Date.Now(); user = Database.findUser(email); SleepUntil(start + MAX_RESPONSE_TIME); return user;
Note: just doing this in your app isn't enough, because you run in a framework and on a virtual server, and things like memory usage affect the speed of these components.
And while you may think that the fact that your app isn't a risk because it doesn't deal with sensitive issues, your users may not agree.
Sometimes security is important. Other times its just a waste of energy.
Site's registration form validation will give the same information and without side-effects.
Step 1: Determine how long a query for a not found user may take... Let's say 1-2 seconds since there may be many rows to deal with.
Step 2: Multiply the value in step 1 by two or at least add a comfortable margin, perhaps 5 seconds total.
Step 3: On the start of the request performing the look up spawn a separate timing thread.
Step 4: At the end of the request join the timing thread.
This will tie the processing time of the request to the uniform time out value instead of your database processing delay.
Let's say a valid login takes 4.9 seconds, and you are able to rig an invalid login to take 5.0 seconds. You might think that is an imperceptible difference. But a determined hacker with a week can try your script a billion times, and get to statistical certainty that the email doesn't exist.
Not sure WHY they'd ever want to go through so much effort for that info, but it's always going to be possible.
Trying to make two code paths take the same time without waiting on an external timer is deep voodoo and should be left to experts.
Shouldn't the best practice of sending emails include using at least some sort of message queue? You're probably right that most web apps will use a synchronous call for this, which is easy to run a timing attack against, but it should be easy to fix this without spending $20k on a security consultant.
(btw: 30x longer is not of interest for timing attacks. If it's 1ns vs 30ns then it's still 30 times longer but doesn't buy the attacker anything when he can only measure ms precision)
Which is why you are you not really adding any security with this stuff by just plugging the obvious holes.
Also, you have to fix this problem every place else that you touch the user database, such as your signup process. There are normally many places you would be affected by the user database, because often the service you provide is slightly different for each user.
But I'm still not convinced that's easily measurable in practice, considering most sendmail implementations dump messages into a queue rather than trying to deliver them immediately.
[1] "If you're registered here, you might be registered with a different email address. If you're not, ignore this one. etc."
Just to be clear, I think the inclusion of screen shots is an excellent use of screen space.
As-is, this is a solid article that I can't send to my team because of that one poor choice.
Here's why:
1) I don't know the personal histories of everyone I work with, and it's none of my business (they aren't expected to tell me).
2) Some people would be seriously distressed to have their boss or co-worker email them anything with remotely sexual content.
3) I can't reliably identify who these people are, and so I simply shouldn't send anything with sexual content to co-workers/employees.
Doesn't this same logic apply to just about everyone?
http://news.ycombinator.com/item?id=4280213
It quickly gained an additional 5 upvotes, and I was looking forward to the HN community's discussion, because I am about to revamp a certain site, and was looking to see what people thought about the specifics listed on that page.
It got to number 7 on the front page at about 11:10. Then it disappeared. It's now down between 900 and 950 or so. Yes, I went and checked.
I was disappointed - I always look forward to in-depth and/or illuminating discussions on HN - but more than that, I'm really curious to know why this item has been flagged so heavily, or, alternatively, buried by the moderators/admins.
So please, here it is again. You're (obviously) free to flag it again if you feel the need, but please, let me know why.
Thanks.
Added in edit: If you upvote this submission then you should probably go upvote grn's original: http://news.ycombinator.com/item?id=4280213 .
It's a minor detail, but an easy one to get right.
http://www.solipsys.co.uk/images/PasswordResetFlow.png
I agree that there's more going on, but this is beyond the original remit. The flowchart can be made seriously more complex by adding in the flow for the simple changing of a password, which needs similar attention to details.
Would you care to assist in producing such a chart? I have provide the DOT source for this image if you like.
Why is this NSFW? The picture does not show nude girls, actually the level of nudity is about what I can get to see in a public pool or on the street on a hot day. The picture certainly is suggestive and hints at something more. The article does not link to a porn site, load images from a porn site or even discuss a porn site. Is the hint that porn sites (or this specific porn site) exists sufficient for the NSFW marker?
I'm asking since this is certainly not considered NSFW for anyone I know - I can see "worse" in respectable TV documentaries which air in the regular evening programme. And I guess there's little chance of minors being around here either.
The other problem I have is, as you say, the image is suggestive. Imagine someone at your office glancing at your monitor whilst walking past. Would they bat an eyelid? I can't think of many workplaces outside of the porn industry where your professionalism wouldn't be called into question, however briefly.
That's not totally true. The screenshot fits perfectly well, because it not only shows the effect of a now know-to-be-known email, it also shows in which context this might be an issue.
Did you not see the word Porn in large, bold white letters against a black background with three young women just underneath it showing ample cleavage in suggestive poses?
There's a time and place for that, work is not one of them. And reading blogs (that are work related) is fine and even encouraged, but visiting sites with graphics like that is not.
[1] For me the "it's interesting and educating" trumps "there's naked women in suggestive poses" any time.
Some US employee avoid anything that could be used against them.
But I am close enough to the US to see why people are nervous. Even acknowledging the existence of porn seems to be enough to make some Americans nervous.
I'm surprised at the number of people here making that many complaints about a PG-13 image, I honestly came here thinking I would see more people making fun of the NSFW warning for being completely reactionary.
Though: when a post from a personal blog makes it to the front page on HN, the author usually finds out fairly quickly, and will read the feedback here.
An easier fix is for users to randomize the email-addresses they use. For example, if you have a Google Mail account, you can receive messages at username+randomdata@gmail.com; if you use different random data for each site, nobody will able to probe for your account as described in the article, even on poorly-designed websites.
The advantage of this approach is that it's something that privacy-minded users can do themselves, without having to rely on website developers to get things right.
The reason it contains this is to illustrate that, if your services says "We have sent an email" vs. "User not found!" then it can leak the information that an account exists for a given email, which may perhaps be embarrassing given the content of the service -- especially if it tells you your User ID.
>> Everything i believe is important
In the spirit of completeness, you could expand the details of this paragraph:
>> What we want to do is create a unique token which can be sent in an email
There should also be a Time to Live on the token, and it should only be usable once. On the landing page for the link, the user needs to enter* their email address to avoid someone arriving at the url from a means other than the original email.
I feel like i should give an example there, let's say the attacker figured out your random id generation method, say it's a hash of a timestamp for simplicity, if they generate a few thousand links for around 6pm, they may get lucky).
* They don't actually need to enter it, UX guys would be having minor heart attacks at that suggestion, but they could choose their email address from a small table of plausible looking but made-up addresses, or something to that effect, e.g. Bank of America uses a photograph the user setup beforehand.
Just $.02 for this conversation :)
Bottom line: never give real answers to secret questions! I can change my password, I can change my credit card if it's compromised, I can even change my social security number if need be, but I can't change the name of my first pet or where I first met my spouse. Never give real answers to secret questions.
As expected, no one has said why it's been flagged.
Unexpected bonus, the original submission has gained enough points to be back on the front page despite having been flagged off it. So that's a win.
Added in edit: Now it's been flagged off again. There are times I really don't like the dynamic on HN.
It might be interesting for one of the sites that scrape HN to reverse engineer the decay factor for different type of stories and find out which stories are "disappeared" quicker.
The reset URL should also expire in about a day, so include and sign timestamp as well.
And the way we know this is good advice is that most large sites do it this way already.
You could include a sequence number in the token, but this, of course, involves a database write, which is what you were trying to avoid in the first place.
A better approach would be to store in the database the time that the user's password was last changed, and refuse to honor any reset tokens that are timestamped prior to that time.
if database.contains(email) or md5sum(secretSalt + email).startsWith('4'):
print "An email has been sent to this address with further instructions"
else:
print "Sorry, this address does not exist in our database"
Now one in 16 (pseudo-randomly selected) emails will appear to be in the database, whether or not it is really there.The attacker will still see the "confirmation" when they enter the victim's email address, but they cannot know if it was really in the database or if it was one of those random false positives.
- contained - false positive - not contained
Probably with the first two being close together and the latter two being close together.
Nice summary, sandstrom. Not as useful as reading the whole article, but much higher value-per-effort. ;)
edit: Not to mention that this chart still leaks the fact that joe@example.com is or is not a member of the site in question.
I'm off to invent distributed processing and BSD sockets.
Despite plenty of guidance to the contrary, the first point is really not where we want to be. The problem with doing this is that it means a persistent password – one you can go back with and use any time
If a developer can't work out how to implement a one-use password that forces a password change after login, they shouldn't be writing code.Sounds pretty far fetched to me.