Breach-Apocalypse
In 2013 over 34 million Americans reported some form of identity theft. Three quarters through 2014 there is already a reported 568 data breaches with over 75 million records compromised and hundreds of millions of users affected. This is up from the 439 breaches in 2013. Identity theft isn't just a possibility, it's a reality that is happening all the time and identity theft is at the core of the second of OWASP's top 10 most critical web security risks of 2013; Broken Authentication and Session Management.
We covered who the Open Web Application Security Project (OWASP) is and their mission in our last article on OWASP's #1 risk; Injection. OWASP has defined Broken Authentication and Session Management as the following:
"Application functions related to authentication and session management are often not implemented correctly, allowing attackers to compromise passwords, keys, or session tokens, or to exploit other implementation flaws to assume other users' identities."
In addition, they have also defined a rating scheme to help clarify the agents, attack vectors and business impact of each risk. The following is how they have defined Broken Authentication and Session Management.
As I described at the beginning, the underlying theme of this risk is the ability of a malicious user to gain access through some other identity. The breadth of various cases that authentication and session management can cover is exhausting. But let's cover some of the obvious common scenarios to get a feel for the attack vectors we need to protect.
To make it easier, we'll break it into the two main areas, credential management and session identification.
Credential Management
When we look at the numerous attack vectors that can account for broken authentication, we can summarize them down to how we manage credentials in our system. A better way to define it is to
ask, how responsible are we with user's identification in our system? Ask yourself, what actions to do you take to protect your personal information and are you taking those same actions for your users?
To paint a mental picture of that last question, when you receive physical mail at your house that retains sensitive information, do you leave it around for the cable guy to see or is it stored away, possibly with the sensitive information being obscured. When you no longer need to retain that information does it just get tossed out with the trash or do you take explicit steps to make it not accessible when it's discarded?
Let's face it, we're not all using the same language and frameworks, nor does the framework you use probably handle all application user requirements. So, the chances that you need to implement a Change Password or Remember Me feature or augment the current framework is pretty high. Implementing a Forgot Password feature? Have you fully vetted the multiple steps involved? We'll look at some of the more common credential management procedures and talk through the points you need to be aware of.
Forgot and Reset Password
Let's make this clear, there isn't a one-size-fits-all security protocol. Depending on your requirements, there is an interacting point where security and user experience meet for your specific scenario. We'll point out those user experiences and security trade-offs as we look through the points of implementing a Forgot Password process.
Forgot Password
We can start by looking at the proper way to handle Forgot Password procedures. There is more to think about than you might originaly imagine.
1. Initialize: To initialize the process of resetting their forgotten password, have users only enter the email address that they believe is associated with the account. Don't provide any feedback on whether the specified email address is valid address or not. Provide only an immediate notification to the end user that instructions for resetting the password was sent to the specified email address.
2. Notify: Immediately send out an email to the specified account despite whether the email is a legitimate address or not. In the case that the email was not legitimate, the email would be a notification to the email holder specifying that no account was found associated with the email. In the case where the email was legitamate, specify the instructions for continuing the password reset process.
Out of the gate, this will be controversial for some, shouting a user-experience foul. There is a small inconvenience where the user must submit another email address due to a typo or incorrect remembrance of what email address was used to register is little when we think about. This small inconvenience affords us additional protection for our users. The larger issue here is allowing a malicious party to harvest information on what valid users exist in our system (including the one experiencing the small inconvenience). The ability to harvest legitimate accounts and information about those accounts is a serious error and will be talked about later at length.
3. Protect the current account: There should be no action taken against an account where a password reset process has been initialized. To be precise, never lockout the account or do not regenerate a new password. Nothing. A form of Denial of Service attack (DOS) can be direct or in mass if any action is taken against an account where only the process of resetting the password has been initialized.
4. Tokenize: Generate a secure token that can be used to identify the reset request. This is persisted with the associated account ID and time stamp of when the request was initialized. This might go without saying, but the token does not represent any sensitive data and is only an obfuscated reference to the request record that should not be able to be guessed.
5. URL: Legitimate email addresses (email addresses found in the system) should contain a URL link to continue the password reset process. The URL will contain the token: https://FluffyKittens.com/account/reset/5hy9285029ki48c862cb9e1893kfjc9 that will be used to look up the password reset request record for additional information. Most importantly, this must be a secured URL using HTTPS. I spoke about the man-in-the-middle vulnerabilities when not securing all aspects of sensitive transaction and this is no different. It might go without saying, but do not provide the user's current password in the email. I might go as far as not even providing the associated username in the email (if the account username isn't the email address). Especially, if you will require further user validation before allowing the user to specify a new password (talked about later in the process).
6. Request Validation: Following the URL link in the email, it will land them on the HTTPS secured form. Before being able to take the next steps in the password reset process, we need to validate that the token provided by the URL is still valid. The time that the request was initialized was captured with the password request record earlier in the process. At this point, you need to apply your business rules for how long a password request is valid, whether that is 1 hour or more. If the time has expired, notify the user that this process must be restarted and discard the reset request record.
7. User: Verification. At this point in the process we have relied completely on the security of the email address. The user is either a legitimate user or someone has managed to compromise the associated email account. Here is where you need to determine what level of further validating the user is required. FluffyKittenWishList.com might not require the same level of validating you are who you claim to be, that your financial institution requires.
There are a number of different forms of validation such as Two-Factor Authentication and Secret Questions/Answers. Since 2FA is in itself a diverse and deep subject, we'll talk shortly about Secret Questions/Answers. If you are determined to further validate the user, they need to answer 1 or more questions that they had chosen and answered at some point in the lifetime of their account. The key however, is that we don't display only the questions they chose to answer. Require the invalidated user to choose from the list of possible questions the correct selected question and provide the correct answer.
If you are using secret questions and answers, the answers need to be stored just as you would with passwords. Many have written long ago how secret answers to secret questions are just another form of a password, so they need to be cryptographically secured.
8. Reset Password: After the user has successfully validated their legitimacy (or in the case where they are not required), they would be presented with the ability to provide a new password (and complementing password confirmation). However, once this has been done, we don't automatically log them in.
9. De-Tokenize: After a successful password reset, destroy the associated password request record that was retrieved using the URL provided token.
10. Notify, Again: Once the password reset is successfully, send a second email to the same email address notifying them that a successful password reset has occurred on the associated account. This might not seem so intuitive, but engineering the compromise of someone's account by someone other than the legitimate owner happens all the time. So, notifying the user account of these types of activities can help mitigate further exploitation of someone's account in the case of an illegitimate password reset.
11. Login: As it was said earlier, when a password is successfully reset, we don't automatically log them in but redirect them to the login page and require them to login.
The preceding is a topic that can be extensively written about (and has been) but I have distilled it down to a few bullet points. Therefore, there are quite a few very important considerations that need to be made that weren't said already, such as:
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Kuppurasu NagarajPosted Apr 11, 2016, 1:55 PM
Nice Sharing
Vithal WadjePosted Oct 21, 2014, 1:38 PM
realy great information,thanks max for sharing,its realy helpful
Arvind PradhanPosted Oct 21, 2014, 5:23 AM
Really Good article................Thank for Sharing This.........