OWASP Top 10 Risks #2: Broken Authentication and Session Management
Join the DZone community and get the full member experience.Join For Free
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 a possibility, it’s a reality that is happening all the time and identity theft is at the core of the 2nd 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 post 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. below 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 malicious user gaining access through some other identity. the breadth of different 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 two main areas, credential management and session identification.
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 users 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 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.
forgot & reset password
let’s make this clear, there isn’t a one size security protocol that fits all. 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 experience and security trade-offs as we look through the points of implementing a forgot password process.
we can start by looking at the proper way to handle forgot password procedures. there is more to think about than you might original 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 a 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.
1. 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 a 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 legit, specify the instructions for continuing the password reset process.
out of the gate, this is going to 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 more precise, no lockout of the account or no re-generation of 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 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 hr. 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 institute 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 talked shortly about secret questions/answers. if you 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 successful, send a second email to the same email address notifying 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 mentioned 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 above 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 mentioned already, such as:
· logging, lots of it. logging every aspect of the reset process (note: never log the password ).
· means for legitimizing the password reset request with captcha’s or throttling requests, usually attempts by harvesters to validate the exists of accounts.
· how to handle cases where username and email are separate but the user has forgotten their associated username – when would be a valid opportunity to divulge this information?
when it comes to allowing password resets by users currently authenticated, the more important factor is ensuring that the currently authenticated users is who we believe them to be. this really can be seen by any computer or device that another user can access physically. whether that is your computer you stepped away from momentarily or a public computer you forgot to log off that website you were logged in.
therefore, a quick and simple way to protect a user’s account is to require they submit the current password along with the new password . additionally, this can be further enforced by requiring further user validation of either in the form of two-factor authentication or secret question/answers.
securing passwords at rest is probably the most popular subject that would also fall under broken authentication. however, one nice aspect of owasp risks is how some areas of individual risks can actually overlap other identified risks. while the mechanism of how we handle password storage in our system relates to broken authentication, it has also been identified as one of the top ten owasp risk at #6: sensitive data exposure .
but, despite having talked about proper password storage before, we’ll look at some of the important points about password storage. the definition of proper password storage has mutated over the years and continues to do so. but with the continued advancements of computer hardware, finding that cryptographically silver bullet that can withstand being cracked is no longer the only angle the community is taking. it now has been coupled with the use of time as a means of defense.
the truth of the matter is that using a good cryptography algorithm can make it hard for a malicious user to crack, but as we have seen too many times, its not impossible. brute force attacks ensure that with some period of time, eventually a password can be cracked. therefore, the ability to slow down how long it takes a malicious user to crack a password plays a significant role in proper password storage.
for some time now, many popular frameworks have been implementing out-of-the-box solutions that incorporate password based key derivation functions such as pbkdf2 and bcrypt. password based key derivation functions take advantage of a process called key stretching. key stretching is the action of deliberately making the key derivation function slow in order to impede attacks such as brute force attacks. it does this by iterating through the hashing algorithm a specified number of times, defined by the iteration count. for example, if the iteration count is set to 12,000, the specified algorithm by the password based key derivation function will iterate the password through the algorithm 12,000.
asp.net’s simplemembershipprovider and identity are two authenticated implementations that utilize the pbkdf2. however, some would argue that their implementation of only 1000 rounds of the hash algorithm is too little. understanding how to implement the pbkdf2 function in .net can help understand how password hashing works in asp.net.
to itemize some core important points to password storage:
· do not store passwords in plain text
· don’t attempt to implement your own hashing schemes – use strong and valid, time proven and tested cryptography algorithms such as asp.net’s identity (be aware of the low 1000 iteration count).
· for scenario’s where implementation is required, use a unique salt with a high level of entropy with each password hash. hash with a valid hashing algorithm such as pbkdf2 and bcrypt with a high level of hashing rounds.
despite not being directly linked to passwords in rest, these are some absolute points of necessities in the grand schemes of password security worth being reminded of:
· always operate under https with any resources that interact with passwords (including the initial authentication form)
· use only “secure” flagged cookies with all https accessed resources
· require strong passwords (preferably minimum of 12 characters), a better option would be to use pass-phrases .
you probably have heard the phrase “defensive driving” or “drive for other people”? the meaning implies that we can’t assume everyone will drive correctly and we must be on guard to protect ourselves from those less skilled drivers. what does that have to do with the topics we have been covering? we can’t think about our users and their information only in the realm of our application. the idea that a third party can garnish information from ‘our’ system about who has a valid account, is a direct security vulnerability. i can you saying “but that is a confidential and privacy issue!”. is it?
let me explain. remember the opening statistics? we all know the probability that a user will use the same email address and password on multiple sites. a user who’s account was compromised on one of those breached systems, has conveniently registered with our system using the same email address and password. allowing the discovery of valid email address in our system can easily lead to an easy illegitimate access to our system through that account. elevated privileged accounts anyone?
how sessions are created, transmitted and disposed is where we see the highest level of vulnerabilities for sessions. as with many frameworks, there is generally a plethora of options for managing session state. this can be in the form of persistence to a database, in-memory cache and even various cloud distributed options. therefore, the ability to cover for each and every scenario is beyond this article.
what we can look at is some important points to be aware of when utilizing session state. at the core of most vulnerabilities with session state, is what we identified at the beginning of this article; stolen identity. the ability for a malicious user to hijack a valid user’s session or impose their own session on a victim is the areas we need to protect against. we’ll start with probably one of the more popular examples and easiest forms of session hijacking.
though, frameworks have taken the liberty to short circuit this vulnerability, the bottom-line is, don’t allow cookie-less sessions . it’s that simple. if this is too hard of a line and cookie-less sessions are a must, then the hardline has to be with not allowing any sensitive data to be transmitted in this scenario. but again, i go back to the first line which is simply don’t allow cookie-less sessions.
session origination & disposure
session id’s need to ensure a high level of entropy to ensure uniqueness as well the inability to be engineered or guessed. in addition, it’s important that sessions are protected. minimum protection should come in the form of the httponly flagged cookies to ensure browser and server only access to session information. however, if any sensitive data is being transmitted, the use of https is absolutely and uncompromisingly required for all session related data.
disposing of sessions is as important as any other part of session security. at minimum there are three pertinent points to maintain when disposing of sessions which are:
1. ensuring that sessions expire and within a reasonable period of time. whether that is 1 day or 1 hr. ensuring that they do expire is pertinent.
2. when disposing of sessions it is absolutely necessary that they completely be invalidated.
3. a invalidated session id should never be recycled for use.
these required security points to how we handle sessions don’t stop with our own managed applications. they also apply (to the extent that they can) with single sign-on tokens issued from other authentication providers.
as you might have gathered from owasp’s definition of broken authentication and session management , is that the realm of possible areas this risk encompasses is overwhelming. application security is a broad subject and authentication and session management is just a piece of the whole pie. however, the impact that these risks can have can be devastating.
what we have seen throughout each of the discussed vulnerable areas is the risk of a identity theft. this can be through exploiting weak authentication or session processes, or through an unsanctioned legit login. it is paramount that we be aware of the vulnerable areas and it is our responsibility to do due diligence when it comes to implementing secure authentication and sessions management.
Published at DZone with permission of Max McCarty, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
WireMock: The Ridiculously Easy Way (For Spring Microservices)
How to Optimize CPU Performance Through Isolation and System Tuning
Integration Testing Tutorial: A Comprehensive Guide With Examples And Best Practices
Which Is Better for IoT: Azure RTOS or FreeRTOS?