4

I've been trying to implement 2FA for a web application, both server and client side. As everybody knows, an H/TOTP is intended to prove that I own something, for example through the use of an authenticator app installed on a mobile phone which will generate the OTP for me.

I'm not sure about what that "something" I own is, so my first question is: is this "something" my phone, or is it the salt for the OTP generation which I load into the app installed on my phone? (If it is the salt, does owning not equate knowing, be it somewhat complicated with an algorithm between me and the salt?)

Given the risk that I loose access to my mobile phone on which I have installed the app, many sites offer me to download backup codes. These codes should be stored in a password manager, just like the password from the first factor. Generally it is possible, after entering my username and password, to bypass the OTP process and enter a backup code through an alternative flow.

My second question is: is my assertion correct that this way the second factor is reduced to something I know, a backup code, and thus merely extending the first factor? (And thus rendering the whole 2FA almost useless, only increasing security a little by adding a second thing I need to know, while increasing the inconvenience of managing more passwords.)

migrated from stackoverflow.com Nov 6 at 1:05

This question came from our site for professional and enthusiast programmers.

5

Does the existence of a recovery code render 2FA useless?

No, for several reasons.

First of all, using a recovery code is very noisy. Using a recovery code is not identical to using a password with a TOTP, so a recovery code should not be seen as "simply an extension of the first factor". So if an attacker would use a recovery code and change your phone number to one that the attacker controls, you can be sure that you would get various notices (e.g. via e-Mail, app notification, etc.). Also if you would contact support immediately, stating that an attacker cracked your recovery code, you would probably have high chances of having your access restored.

Secondly, it's recommended not to store a recovery code in the same location as your passwords. Storing your passwords in a Keepass database is a good idea. Recovery codes, however, should not be stored there. I would recommend writing them on a sheet of paper and sticking it in a folder with other important documents (preferably in a safe, or similar). This way, an attacker that gains access to your Keepass database and is able to crack the password of that database, doesn't have access to both password and recovery code.

That way, in order to steal your recovery code, an attacker would either have to guess it (which should be impossible with a recovery code like Lining Everybody Frays Overpay Swinger Boogeyman Rise Anvil Pastel Quaking), or gain access to your home (at which point the security of your GitHub account is probably secondary).

  • If I present my backup/recovery code (which was provided to me by the application) all I prove is that I "know" a backup code that is also in the application database linked to my account. I doesn't prove anything about me "having" something, which is what the second factor is all about. – scola Nov 8 at 12:25
  • That is also not the purpose of a backup code. A backup code isn't "my phone isn't at hand, just use this code instead" - it's "I lost access to my second factor. Here is the backup code to prove it's really me. Please do something!". The point is that a password plus a backup code is not identical to a password and a token from a second factor. – MechMK1 Nov 8 at 12:27
  • This is the process as I have found it implemented in several sites: 1. Enter username/password. 2a. Enter TOTP or (if you lost access to the second factor) 2b. Enter backup codes. In the case of 1 + 2b (which is and always will have to be accessible for every user) the login process has been reduced to 2 things I know: my password and a backup code. So indeed, password + backup is not identical to password + token, and that is exactly the problem. – scola Nov 8 at 12:49
  • 1
    If a website treats login with a recovery code identical to login with a regular second factor, then that is the actual problem. A recovery code being used should always be treated as an exceptional case, not as regular. – MechMK1 Nov 8 at 12:51
  • But it is exactly the way how e.g. Github works. If I enable 2FA in Github, then, when I login with my username and password, I am requested to enter the TOTP or go to a seperate page where I can enter a backup code. This is necessary, because if I had lost my authenticator app, I would be locked out forever, if there would be no possiblity bypass it and go to the backup code page immediately after I had entered my username/password. So, username/password + backup code is a necessary flow, but it is the weakest link in the defence mechanism, and thus reduces 2FA to 1FA – scola Nov 13 at 10:41
0

You should not store both the passwords and your backup codes in your password manager due to the problem your describing. I would propose you store it separated. For example a USB drive in a safe or a sheet of paper stored within your personal documents would be a better place for your recovery codes. Then an attacker needs to have access to your home as well.

  • Writing down the backup codes or putting them on a USB drive, doesn't change the nature of the codes. Otherwise, writing down the password would change the password into something I 'have', too. – scola Nov 8 at 12:27
  • Thank you for pointing this out, your correct. My point was more that it is still useful and I will try to change the answer accordingly. – LittleBobbyTable Nov 8 at 13:57
0

A backup code is a recovery mechanism, and I second what MechMK1 said about not storing them in the same place as the passwords. I also have them printed and stored with various "important" papers in a drawer at home.

As such, the way it is used, the way it is meant to be stored long-term, even if the website does not offer guidance (which it should, ideally, but many don't), means that you cannot look at it only from the "something I know [etc]" point of view. It's beyond that.

  • Why is it beyond that. The second factor in 2FA is about proving that you own something. A printed backup code is nothing something you own, as I have pointed out in security.stackexchange.com/a/220785/221167. – scola Nov 13 at 10:44
  • We're arguing semantics here. If you want to say "backup codes are not 2FA" that's fine; the fact is they're a recovery mechanism, while 2FA is for day-to-day use. And because they are so "powerful" yet not 2FA, they need to be protected correspondingly well -- such as keeping only a printed copy in a safe. – sitaram Nov 13 at 22:23
  • But as a recovery mechanism, necessarily always accessible after you entered username/password as a bypass around 2FA, because otherwise a loss of your TOTP generator would lock you out forever, backup codes reduce the defense mechanism to 1FA. The defense is as strong as its weakest part, which is the backup code in this case. – scola Nov 14 at 7:06
  • A backup code is not weak if you store it properly. That's the whole point of printing it and keeping it in a safe. I guess you have a different definition of "weak". To each his own.. – sitaram Nov 14 at 11:08
  • The strength of a security credential/token is an intrinsic quality of the credential/token itself (its unpredictability by virtue of e.g. its randomness), and is not determined by its storage. (Storing "abcd" properly doesn't make it a strong password.) But I should have said: the recovery mechanism based on backup codes is the weakest part, because it becomes possible to gain access to the system through presenting two things you know, the username/password and the backup code, and no longer one thing you know and one thing you have (which is prerequisite for a proper 2FA implementation). – scola Nov 14 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.