Difference between revisions of "Authentication Cheat Sheet"

From OWASP
Jump to: navigation, search
m (Implement Secure Password Recovery Mechanism)
m
(22 intermediate revisions by 8 users not shown)
Line 3: Line 3:
 
'''Authentication''' is the process of verification that an individual or an entity is who it claims to be. Authentication is commonly performed by submitting a user name or ID and one or more items of private information that only a given user should know.  
 
'''Authentication''' is the process of verification that an individual or an entity is who it claims to be. Authentication is commonly performed by submitting a user name or ID and one or more items of private information that only a given user should know.  
  
'''Session Management''' is a process by which a server maintains the state of an entity interacting with it. This is required for a server to remember how to react to subsiquent requests throughout a transaction. Sessions are maintained on the server by a session identifier which can be passed back and forward between the client and server when mtransmitting and receiving requests. Sessions should be unique per user and computationally very difficult to predict.  
+
'''Session Management''' is a process by which a server maintains the state of an entity interacting with it. This is required for a server to remember how to react to subsequent requests throughout a transaction. Sessions are maintained on the server by a session identifier which can be passed back and forward between the client and server when transmitting and receiving requests. Sessions should be unique per user and computationally very difficult to predict.  
  
For more information on Authentication, please see the OWASP [[Guide to Authentication]] page.  
+
For more information on Authentication, please see the OWASP [[Guide to Authentication]] page.
  
 
= Authentication General Guidelines  =
 
= Authentication General Guidelines  =
  
== Implement Proper Password Strength Controls  ==
+
== User IDs ==
  
A key concern when using passwords for authentication is password strength. A "strong" password policy makes it difficult or even improbable for one to guess the password either by using manual or automated means. The following characteristics define strong a strong password:
+
Make sure your usernames/userids are case insensitive. Many sites use email addresses for usernames and email addresses are already case insensitive. Regardless, it would be very strange for user 'smith' and user 'Smith' to be different users. Could result in serious confusion.
  
=== Password Length  ===
+
== Implement Proper Password Strength Controls ==
  
The longer the password the more combinations possible combinations of characters exist and is hence more difficult to guess.  
+
A key concern when using passwords for authentication is password strength. A "strong" password policy makes it difficult or even improbable for one to guess the password through either manual or automated means. The following characteristics define a strong password:
  
'''Important applications''': Minimum of 6 characters in length.
+
=== Password Length ===
  
'''Critical applications''': Minimum of 8 characters in length. (consider multi-factor authentication)
+
Longer passwords provide a greater combination of characters and consequently make it more difficult for an attacker to guess.  
  
'''Highly critical applications''': Consider multi-factor authentication
+
* '''Minimum''' length of the passwords should be '''enforced''' by the application.
 +
** Passwords '''shorter than 10 characters''' are considered to be weak ([http://csrc.nist.gov/publications/nistpubs/800-132/nist-sp800-132.pdf]).
  
=== Password complexity  ===
+
While minimum length enforcement may cause problems with memorizing passwords among some users, applications should encourage them to set ''passphrases'' (sentences or combination of words) that can be much longer than typical passwords and yet much easier to remember.
  
'''Example'''<br>Passwords should be checked for the following composition or a variance of such:
+
* '''Maximum''' password length should not be set '''too low''', as it will prevent users from creating passphrases. Typical maximum length is 128 characters.
 +
** Passphrases shorter than 20 characters are usually considered weak if they only consist of lower case Latin characters.
  
*at least: 1 uppercase character (A-Z)
+
* Every character counts!!
*at least: 1 lowercase character (a-z)
+
**Make sure that every character the user types in is actually included in the password. We've seen systems that truncate the password at a length shorter than what the user provided (e.g., truncated at 15 characters when they entered 20).
*at least: 1 digit (0-9)
+
**This is usually handled by setting the length of ALL password input fields to be exactly the same length as the maximum length password. This is particularly important if your max password length is short, like 20-30 characters.
*at least one special character (!"£$%&amp;...)
+
*a defined minimum length (e.g. 8 chars)  
+
*a defined maximum length (as with all external input)
+
*no contiguous characters (e.g. 123abcd)
+
*not more than 2 identical characters in a row (1111)
+
  
== Implement Secure Password Recovery Mechanism  ==
+
=== Password Complexity ===
  
It is common for an application to have a mechanism that provides a means for a user to gain access to their account in the event they forget their password. Please see [https://www.owasp.org/index.php/Forgot_Password_Cheat_Sheet https://www.owasp.org/index.php/Forgot_Password_Cheat_Sheet] for details on this feature.
+
Applications should enforce password complexity rules to discourage easy to guess passwords. Password mechanisms should allow virtually any character the user can type to be part of their password, including the space character. Passwords should, obviously, be case sensitive in order to increase their complexity. Occasionally, we find systems where passwords aren't case sensitive, frequently due to legacy system issues like old mainframes that didn't have case sensitive passwords.
  
== Utilize Multi-Factor Authentication  ==
+
The password change mechanism should require a minimum level of complexity that makes sense for the application and its user population. For example:
  
Multifactor factor authentication is using more than one of:
+
*Password must meet at least 3 out of the following 4 complexity rules
 +
**at least 1 uppercase character (A-Z)
 +
**at least 1 lowercase character (a-z)
 +
**at least 1 digit (0-9)
 +
**at least 1 special character (!"£$%&amp;...) &mdash; do not forget to treat space as special characters (common in passphrases)
 +
*at least 10 characters
 +
*at most 128 characters
 +
*not more than 2 identical characters in a row (e.g., 111 not allowed)
  
*Something you know (account details or passwords)
+
As application's require more complex password policies, they need to be very clear about what these policies are.
*Something you have (tokens or mobile phones)
+
*The required policy needs to be explicitly stated on the password change page
*Something you are (biometrics)
+
** be sure to list every special character you allow, so it's obvious to the user
  
to logon or process a transaction.  
+
Recommendation:
 +
* Ideally, the application would indicate to the user as they type in their new password how much of the complexity policy their new password meets
 +
**In fact, the submit button should be grayed out until the new password meets the complexity policy and the 2nd copy of the new password matches the 1st. This will make it far easier for the user to understand and comply with your complexity policy.
  
Authentication schemes such as One Time Passwords (OTP) implemented using a hardware token can also be&nbsp;key&nbsp;in fighting attacks such as CSRF and client-side malware.
+
Regardless of how the UI behaves, when a user submits their password change request:
 +
*If the new password doesn't comply with the complexity policy, the error message should describe EVERY complexity rule that the new password does not comply with, not just the 1st rule it doesn't comply with
  
== Authentication and Error Messages  ==
+
Changing passwords should be EASY, not a hunt in the dark.
  
Incorrectly implemented error messages in the case of authentication functionality can be used for the purposes of user ID and password enumeration.
+
== Implement Secure Password Recovery Mechanism ==
  
'''An application should respond (both HTTP and HTML)&nbsp;in a generic manner which is not unique to the error condition or authentication failure.'''
+
It is common for an application to have a mechanism that provides a means for a user to gain access to their account in the event they forget their password. Please see [[Forgot_Password_Cheat_Sheet]] for details on this feature.
  
==== Authentication responses  ====
+
== Require Re-authentication for Sensitive Features ==
  
An application should respond with a generic error message regardless if the user ID or password was incorrect. It should also no give any indication to the status of an account if it exists.  
+
In order to mitigate CSRF and session hijacking, it's important to require the current credentials for an account before updating sensitive account information such as the user's password, user's email, or before sensitive transactions, such as shipping a purchase to a new address. Without this countermeasure, an attacker may be able to execute sensitive transactions through a CSRF or XSS attack without needing to know the user's current credentials.  Additionally, an attacker may get temporary physical access to a user's browser or steal their session ID to take over the user's session.
  
==== Incorrect responses examples  ====
+
== Utilize Multi-Factor Authentication ==
  
*"Login for User foo: invalid password"
+
Multi-factor authentication (MFA) is using more than one authentication factor to logon or process a transaction:
*"Login failed, invalid user ID"
+
*"Login failed; account disabled"
+
*"login failed; this user is not active"
+
  
==== Correct response example  ====
+
*Something you know (account details or passwords)
 +
*Something you have (tokens or mobile phones)
 +
*Something you are (biometrics)
  
*"Login failed; Invalid user&nbsp;ID or password"
+
Authentication schemes such as One Time Passwords (OTP) implemented using a hardware token can also be key in fighting attacks such as CSRF and client-side malware. A number of hardware tokens suitable for MFA are available in the market that allow good integration with web applications. See: [http://en.wikipedia.org/wiki/Security_token].
  
The correct response does not indicate if the user ID or password is the incorrect parameter and hence inferring a valid user ID.
+
== Authentication and Error Messages ==
  
==== Error Codes and URL's  ====
+
Incorrectly implemented error messages in the case of authentication functionality can be used for the purposes of user ID and password enumeration. An application should respond (both HTTP and HTML) in a generic manner.
  
The application may return a different HTTP Error code depending on the authentication attempt response. It&nbsp;may respond with a 200 for a positive result and a 403 for a negative result. Even though a generc error page is shown to a user the HTTP response code may differ which can indicate a signature.
+
==== Authentication Responses ====
  
== Transmit Passwords Only Over TLS  ==
+
An application should respond with a generic error message regardless of whether the user ID or password was incorrect. It should also give no indication to the status of an existing account.
  
See: "Transport Layer Protection Cheat Sheet"
+
==== Incorrect Response Examples ====
  
[http://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet http://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet]
+
*"Login for User foo: invalid password"
 +
*"Login failed, invalid user ID"
 +
*"Login failed; account disabled"
 +
*"Login failed; this user is not active"
  
"The login page and all subsequent authenticated pages must be exclusively accessed over TLS. The initial login page, referred to as the "login landing page", must be served over TLS. Failure to utilize TLS for the login landing page allows an attacker to modify the login form action, causing the user's credentials to be posted to an arbitrary location. Failure to utilize TLS for authenticated pages after the login enables an attacker to view the unencrypted session ID and compromise the user's authenticated session."
+
==== Correct Response Example ====
  
== Implement Account Lockout  ==
+
*"Login failed; Invalid userID or password"
  
If an attacker is able to guess passwords without the account becoming disabled due to failed authentication attempts, this&nbsp;provides the opportunity of the attacked to continue with a brute force attack until the account is compromised.  
+
The correct response does not indicate if the user ID or password is the incorrect parameter and hence inferring a valid user ID.  
  
Automating brute-force/password guessing attacks on web applications is a trivial challenge. Password lockout mechanisms should be employed that lock out an account if more than a preset number of unsuccessful login attempts are made.
+
==== Error Codes and URL's ====
  
Password lockout mechanisms do have a logical&nbsp;weakness, however. It is possible for an&nbsp;attacker to attempt a large number of authentication attempts&nbsp;on known account names resulting in locking out entire blocks of application&nbsp;users accounts.  
+
The application may return a different HTTP Error code depending on the authentication attempt response. It may respond with a 200 for a positive result and a 403 for a negative result. Even though a generic error page is shown to a user, the HTTP response code may differ which can leak information about whether the account is valid or not.
  
Given that the intent of a password lockout system is to protect from brute-force attacks, a sensible strategy is to lockout accounts for a number of hours. This significantly slows down attackers, while allowing the accounts to be open for legitimate users.
+
== Transmit Passwords Only Over TLS ==
  
See also "Reverse Brute-force" [[Reverse Brute Force|Reverse_Brute_Force]]
+
See: [[Transport Layer Protection Cheat Sheet]]
  
= Session Management General Guidelines  =
+
The login page and all subsequent authenticated pages must be exclusively accessed over TLS. The initial login page, referred to as the "login landing page", must be served over TLS. Failure to utilize TLS for the login landing page allows an attacker to modify the login form action, causing the user's credentials to be posted to an arbitrary location. Failure to utilize TLS for authenticated pages after the login enables an attacker to view the unencrypted session ID and compromise the user's authenticated session.
  
== Transmit Session ID's Only Over TLS  ==
+
== Implement Account Lockout ==
  
Session ID's should be transmitted over a secure TLS channel.  
+
If an attacker is able to guess passwords without the account becoming disabled due to failed authentication attempts, the attacker has an opportunity to continue with a brute force attack until the account is compromised.  
  
A browser directive, the secure flag, for the cookie exists which instructs the browser at the set-cookie action only to send over a secure channel.  
+
Automating brute-force/password guessing attacks on web applications is a trivial challenge. Password lockout mechanisms should be employed that lock out an account if more than a preset number of unsuccessful login attempts are made.  
  
This prevents attacks such as Man-in-the-Middle (MitM) and surf jacking attacks.
+
Password lockout mechanisms have a logical weakness. An attacker that undertakes a large number of authentication attempts on known account names can produce a result that locks out entire blocks of user accounts.  
  
== Ensure Session ID's are Cryptographically Strong and Random  ==
+
Given that the intent of a password lockout system is to protect from brute-force attacks, a sensible strategy is to lockout accounts for a period of time (e.g., 20 minutes). This significantly slows down attackers, while allowing the accounts to reopen automatically for legitimate users.
  
Session ID's should be large and random enough such that they are not easily predicted. This may lead to session hijacking and identity theft.
+
= Session Management General Guidelines  =
  
Be sure the session ID used has the following traits at a minimum:  
+
Session management is directly related to authentication. The '''Session Management General Guidelines''' previously available on this OWASP Authentication Cheat Sheet have been integrated into the new [https://www.owasp.org/index.php/Session_Management_Cheat_Sheet OWASP Session Management Cheat Sheet].
  
*Session identifiers should be at least 128 bits long to prevent brute-force session guessing attacks.
+
= Password Managers =
*All session identifiers should be sufficiently randomized so as to not be guessable.
+
*All session identifiers should use the largest character set available to it.
+
  
Also see: http://www.owasp.org/index.php/Insufficient_Session-ID_Length http://www.owasp.org/index.php/Session_Management
+
Password managers are programs, browser plugins or web services that automate management of large number of different credentials, including memorizing and filling-in, generating random passwords on different sites etc. The web application can help password managers by:
  
== Implement Idle And Absolute Timeout  ==
+
* using standard HTML forms for username and password input,
 
+
* not using multi-stage login schemes (username on first screen, then password),
=== Session Idle Timeout  ===
+
* not using highly scripted (JavaScript) authentication schemes.
 
+
All browser sessions should implement an inactivity timeout.
+
 
+
An inactivity timeout closes/invalidates a session upon a period of inactivity (Server has not received a request for a given session ID) has been reached.
+
 
+
=== Session Absolute Timeout  ===
+
 
+
Regardless of session/user activity is is recommended to enforce a session timeout "maximum time limit" if possible. This maximum session time invalidates the users session and forces them to log into the application again by re-authentication. If a session was hijacked via cookie theft, an absolute timeout may limit exposure to the user.
+
 
+
== Cookie Security  ==
+
 
+
=== Secure Flag  ===
+
 
+
If the site requires operation over SSL ensure the secure flag is set upon the set-cookie directive sent the to the browser.
+
 
+
=== HTTP Only  ===
+
 
+
The HTTP only directive, also sent to the browser can project the cookie from JavaScript manupulation. This is a compensating control against XSS cookie attacks.
+
 
+
=== HTTP GET Vs POST  ===
+
 
+
Sending any sensitive data over a query string, using HTTP GET can give rise to information leakage at points through the traffic path&nbsp;or at either end of the SSL tunnel:
+
 
+
E.g. Logs (firewall, Router, TLS tunnel terminator, App/web server).  
+
 
+
Query strings can also be cached in a browser's history.
+
 
+
Authentication over Query String regardless of the use of SSL&nbsp;is not recommended.
+
 
+
= Related Articles  =
+
 
+
{{Cheatsheet_Navigation}}
+
  
 
= Authors and Primary Editors  =
 
= Authors and Primary Editors  =
Line 161: Line 136:
 
Eoin Keary eoinkeary[at]owasp.org  
 
Eoin Keary eoinkeary[at]owasp.org  
  
[[Category:How_To]] [[Category:Cheatsheets]] [[Category:OWASP_Document]] [[Category:OWASP_Top_Ten_Project]]
+
= Other Cheatsheets =
 +
{{Cheatsheet_Navigation}}
 +
 
 +
[[Category:Cheatsheets]]

Revision as of 05:02, 24 January 2013

Contents

Introduction

Authentication is the process of verification that an individual or an entity is who it claims to be. Authentication is commonly performed by submitting a user name or ID and one or more items of private information that only a given user should know.

Session Management is a process by which a server maintains the state of an entity interacting with it. This is required for a server to remember how to react to subsequent requests throughout a transaction. Sessions are maintained on the server by a session identifier which can be passed back and forward between the client and server when transmitting and receiving requests. Sessions should be unique per user and computationally very difficult to predict.

For more information on Authentication, please see the OWASP Guide to Authentication page.

Authentication General Guidelines

User IDs

Make sure your usernames/userids are case insensitive. Many sites use email addresses for usernames and email addresses are already case insensitive. Regardless, it would be very strange for user 'smith' and user 'Smith' to be different users. Could result in serious confusion.

Implement Proper Password Strength Controls

A key concern when using passwords for authentication is password strength. A "strong" password policy makes it difficult or even improbable for one to guess the password through either manual or automated means. The following characteristics define a strong password:

Password Length

Longer passwords provide a greater combination of characters and consequently make it more difficult for an attacker to guess.

  • Minimum length of the passwords should be enforced by the application.
    • Passwords shorter than 10 characters are considered to be weak ([1]).

While minimum length enforcement may cause problems with memorizing passwords among some users, applications should encourage them to set passphrases (sentences or combination of words) that can be much longer than typical passwords and yet much easier to remember.

  • Maximum password length should not be set too low, as it will prevent users from creating passphrases. Typical maximum length is 128 characters.
    • Passphrases shorter than 20 characters are usually considered weak if they only consist of lower case Latin characters.
  • Every character counts!!
    • Make sure that every character the user types in is actually included in the password. We've seen systems that truncate the password at a length shorter than what the user provided (e.g., truncated at 15 characters when they entered 20).
    • This is usually handled by setting the length of ALL password input fields to be exactly the same length as the maximum length password. This is particularly important if your max password length is short, like 20-30 characters.

Password Complexity

Applications should enforce password complexity rules to discourage easy to guess passwords. Password mechanisms should allow virtually any character the user can type to be part of their password, including the space character. Passwords should, obviously, be case sensitive in order to increase their complexity. Occasionally, we find systems where passwords aren't case sensitive, frequently due to legacy system issues like old mainframes that didn't have case sensitive passwords.

The password change mechanism should require a minimum level of complexity that makes sense for the application and its user population. For example:

  • Password must meet at least 3 out of the following 4 complexity rules
    • at least 1 uppercase character (A-Z)
    • at least 1 lowercase character (a-z)
    • at least 1 digit (0-9)
    • at least 1 special character (!"£$%&...) — do not forget to treat space as special characters (common in passphrases)
  • at least 10 characters
  • at most 128 characters
  • not more than 2 identical characters in a row (e.g., 111 not allowed)

As application's require more complex password policies, they need to be very clear about what these policies are.

  • The required policy needs to be explicitly stated on the password change page
    • be sure to list every special character you allow, so it's obvious to the user

Recommendation:

  • Ideally, the application would indicate to the user as they type in their new password how much of the complexity policy their new password meets
    • In fact, the submit button should be grayed out until the new password meets the complexity policy and the 2nd copy of the new password matches the 1st. This will make it far easier for the user to understand and comply with your complexity policy.

Regardless of how the UI behaves, when a user submits their password change request:

  • If the new password doesn't comply with the complexity policy, the error message should describe EVERY complexity rule that the new password does not comply with, not just the 1st rule it doesn't comply with

Changing passwords should be EASY, not a hunt in the dark.

Implement Secure Password Recovery Mechanism

It is common for an application to have a mechanism that provides a means for a user to gain access to their account in the event they forget their password. Please see Forgot_Password_Cheat_Sheet for details on this feature.

Require Re-authentication for Sensitive Features

In order to mitigate CSRF and session hijacking, it's important to require the current credentials for an account before updating sensitive account information such as the user's password, user's email, or before sensitive transactions, such as shipping a purchase to a new address. Without this countermeasure, an attacker may be able to execute sensitive transactions through a CSRF or XSS attack without needing to know the user's current credentials. Additionally, an attacker may get temporary physical access to a user's browser or steal their session ID to take over the user's session.

Utilize Multi-Factor Authentication

Multi-factor authentication (MFA) is using more than one authentication factor to logon or process a transaction:

  • Something you know (account details or passwords)
  • Something you have (tokens or mobile phones)
  • Something you are (biometrics)

Authentication schemes such as One Time Passwords (OTP) implemented using a hardware token can also be key in fighting attacks such as CSRF and client-side malware. A number of hardware tokens suitable for MFA are available in the market that allow good integration with web applications. See: [2].

Authentication and Error Messages

Incorrectly implemented error messages in the case of authentication functionality can be used for the purposes of user ID and password enumeration. An application should respond (both HTTP and HTML) in a generic manner.

Authentication Responses

An application should respond with a generic error message regardless of whether the user ID or password was incorrect. It should also give no indication to the status of an existing account.

Incorrect Response Examples

  • "Login for User foo: invalid password"
  • "Login failed, invalid user ID"
  • "Login failed; account disabled"
  • "Login failed; this user is not active"

Correct Response Example

  • "Login failed; Invalid userID or password"

The correct response does not indicate if the user ID or password is the incorrect parameter and hence inferring a valid user ID.

Error Codes and URL's

The application may return a different HTTP Error code depending on the authentication attempt response. It may respond with a 200 for a positive result and a 403 for a negative result. Even though a generic error page is shown to a user, the HTTP response code may differ which can leak information about whether the account is valid or not.

Transmit Passwords Only Over TLS

See: Transport Layer Protection Cheat Sheet

The login page and all subsequent authenticated pages must be exclusively accessed over TLS. The initial login page, referred to as the "login landing page", must be served over TLS. Failure to utilize TLS for the login landing page allows an attacker to modify the login form action, causing the user's credentials to be posted to an arbitrary location. Failure to utilize TLS for authenticated pages after the login enables an attacker to view the unencrypted session ID and compromise the user's authenticated session.

Implement Account Lockout

If an attacker is able to guess passwords without the account becoming disabled due to failed authentication attempts, the attacker has an opportunity to continue with a brute force attack until the account is compromised.

Automating brute-force/password guessing attacks on web applications is a trivial challenge. Password lockout mechanisms should be employed that lock out an account if more than a preset number of unsuccessful login attempts are made.

Password lockout mechanisms have a logical weakness. An attacker that undertakes a large number of authentication attempts on known account names can produce a result that locks out entire blocks of user accounts.

Given that the intent of a password lockout system is to protect from brute-force attacks, a sensible strategy is to lockout accounts for a period of time (e.g., 20 minutes). This significantly slows down attackers, while allowing the accounts to reopen automatically for legitimate users.

Session Management General Guidelines

Session management is directly related to authentication. The Session Management General Guidelines previously available on this OWASP Authentication Cheat Sheet have been integrated into the new OWASP Session Management Cheat Sheet.

Password Managers

Password managers are programs, browser plugins or web services that automate management of large number of different credentials, including memorizing and filling-in, generating random passwords on different sites etc. The web application can help password managers by:

  • using standard HTML forms for username and password input,
  • not using multi-stage login schemes (username on first screen, then password),
  • not using highly scripted (JavaScript) authentication schemes.

Authors and Primary Editors

Eoin Keary eoinkeary[at]owasp.org

Other Cheatsheets

OWASP Cheat Sheets Project Homepage

Developer Cheat Sheets (Builder)

Assessment Cheat Sheets (Breaker)

Mobile Cheat Sheets

OpSec Cheat Sheets (Defender)

Draft Cheat Sheets