524
can confuse users) or being too detailed (which may reveal more than intended). The messages
should not reveal the methods that were used to determine the error. Attackers can use detailed
information to refine or optimize their original attack, thereby increasing their chances of success.
If errors must be captured in some detail, record them in log messages, but consider what
could occur if the log messages can be viewed by attackers. Highly sensitive information such
as passwords should never be saved to log files. Avoid inconsistent messaging that might
accidentally tip off an attacker about internal state, such as whether a user account exists or not.
Demonstrative Examples
Example 1:
The following code checks validity of the supplied username and password and notifies the user of
a successful or failed login.
Example Language: Perl (Bad)
my $username=param('username');
my $password=param('password');
if (IsValidUsername($username) == 1)
{
if (IsValidPassword($username, $password) == 1)
{
print "Login Successful";
}
else
{
print "Login Failed - incorrect password";
}
}
else
{
print "Login Failed - unknown username";
}
In the above code, there are different messages for when an incorrect username is supplied,
versus when the username is correct but the password is wrong. This difference enables a
potential attacker to understand the state of the login function, and could allow an attacker
to discover a valid username by trying different values until the incorrect password message
is returned. In essence, this makes it easier for an attacker to obtain half of the necessary
authentication credentials.
While this type of information may be helpful to a user, it is also useful to a potential attacker. In the
above example, the message for both failed cases should be the same, such as:
Example Language: (Result)
"Login Failed - incorrect username or password"
Observed Examples
Reference Description
CVE-2002-2094 This, and others, use ".." attacks and monitor error responses, so there is
overlap with directory traversal.
https://www.cve.org/CVERecord?id=CVE-2002-2094
CVE-2001-1483 Enumeration of valid usernames based on inconsistent responses
https://www.cve.org/CVERecord?id=CVE-2001-1483
CVE-2001-1528 Account number enumeration via inconsistent responses.
https://www.cve.org/CVERecord?id=CVE-2001-1528
CVE-2004-2150 User enumeration via discrepancies in error messages.
https://www.cve.org/CVERecord?id=CVE-2004-2150
CVE-2005-1650 User enumeration via discrepancies in error messages.
CWE Version 4.14
CWE-204: Observable Response Discrepancy
CWE-204: Observable Response Discrepancy