468
For example, an attacker might succeed in authentication by providing a small password that
matches the associated portion of the larger, correct password.
Relationships
The table(s) below shows the weaknesses and high level categories that are related to this
weakness. These relationships are defined as ChildOf, ParentOf, MemberOr and give insight to
similar items that may exist at higher and lower levels of abstraction. In addition, relationships such
as PeerOf and CanAlsoBe are defined to show similar weaknesses that may want to be explored.
Relevant to the view "Research Concepts" (CWE-1000)
Nature Type ID Name Page
ChildOf 1023 Incomplete Comparison with Missing Factors 1865
PeerOf 625 Permissive Regular Expression 1392
CanFollow 185 Incorrect Regular Expression 463
Weakness Ordinalities
Primary :
Applicable Platforms
Language : Not Language-Specific (Prevalence = Undetermined)
Common Consequences
Scope Impact Likelihood
Integrity
Access Control
Alter Execution Logic
Bypass Protection Mechanism
Potential Mitigations
Phase: Testing
Thoroughly test the comparison scheme before deploying code into production. Perform positive
testing as well as negative testing.
Demonstrative Examples
Example 1:
This example defines a fixed username and password. The AuthenticateUser() function is intended
to accept a username and a password from an untrusted user, and check to ensure that it matches
the username and password. If the username and password match, AuthenticateUser() is intended
to indicate that authentication succeeded.
Example Language: C (Bad)
/* Ignore CWE-259 (hard-coded password) and CWE-309 (use of password system for authentication) for this example. */
char *username = "admin";
char *pass = "password";
int AuthenticateUser(char *inUser, char *inPass) {
if (strncmp(username, inUser, strlen(inUser))) {
logEvent("Auth failure of username using strlen of inUser");
return(AUTH_FAIL);
}
if (! strncmp(pass, inPass, strlen(inPass))) {
logEvent("Auth success of password using strlen of inUser");
return(AUTH_SUCCESS);
}
else {
logEvent("Auth fail of password using sizeof");
return(AUTH_FAIL);
}
}
int main (int argc, char **argv) {
int authResult;
CWE Version 4.14
CWE-187: Partial String Comparison
CWE-187: Partial String Comparison