CWE-287

Improper Authentication. [Improper-Access-Control, Top25-2024-14]

Required inputs: IR

When an actor claims to have a given identity, the product does not prove or insufficiently proves that the claim is correct.
Demonstrative Examples Functional Areas
Example 1

The following code intends to ensure that the user is already logged in. If not, the code performs authentication with the user-provided username and password. If successful, it sets the loggedin and user cookies to "remember" that the user has already logged in. Finally, the code performs administrator tasks if the logged-in user has the "Administrator" username, as recorded in the user cookie.

Example Language:Perl (Unsupported language for documentation only)
    my $q = new CGI;

    if ($q->cookie('loggedin') ne "true") {
        if (! AuthenticateUser($q->param('username'), $q->param('password'))) {
            ExitError("Error: you need to log in first");
        }
        else {
            # Set loggedin and user cookies.
            $q->cookie(
                -name => 'loggedin',
                -value => 'true'
                );

            $q->cookie(
                -name => 'user',
                -value => $q->param('username')
                );
        }
    }

    if ($q->cookie('user') eq "Administrator") {
        DoAdministratorTasks();
    }

Unfortunately, this code can be bypassed. The attacker can set the cookies independently so that the code does not check the username and password. The attacker could do this with an HTTP request containing headers such as:

(attack code)

    GET /cgi-bin/vulnerable.cgi HTTP/1.1
    Cookie: user=Administrator
    Cookie: loggedin=true

    [body of request]

By setting the loggedin cookie to "true", the attacker bypasses the entire authentication check. By using the "Administrator" value in the user cookie, the attacker also gains privileges to administer the software.

Example 2

In January 2009, an attacker was able to gain administrator access to a Twitter server because the server did not restrict the number of login attempts [REF-236]. The attacker targeted a member of Twitter's support team and was able to successfully guess the member's password using a brute force attack by guessing a large number of common words. After gaining access as the member of the support staff, the attacker used the administrator panel to gain access to 33 accounts that belonged to celebrities and politicians. Ultimately, fake Twitter messages were sent that appeared to come from the compromised accounts.

Example 3

In 2022, the OT:ICEFALL study examined products by 10 different Operational Technology (OT) vendors. The researchers reported 56 vulnerabilities and said that the products were "insecure by design" [REF-1283]. If exploited, these vulnerabilities often allowed adversaries to change how the products operated, ranging from denial of service to changing the code that the products executed. Since these products were often used in industries such as power, electrical, water, and others, there could even be safety implications.

Multiple vendors did not use any authentication or used client-side authentication for critical functionality in their OT products.

Demonstrative Examples Functional Areas
  • Authentication
Excerpts from CWE [https://cwe.mitre.org], Copyright (C) 2006-2026, the MITRE Corporation. See section 9.4. "3rd-Party Licenses" in the documentation for full details.

Possible Messages

Key

Text

Severity

Disabled

assignment

Assigning a literal to a variable holding a password.

None

False

comparison

Comparing a literal to a password.

None

False

key

The string literal might include a private key.

None

False

parameter

Passing a literal to a password parameter.

None

False

return

Returning a literal as a password.

None

False

Options

critical_routines_pattern

critical_routines_pattern : typing.Pattern[str] = 'authenticate'

Routines with a fully qualified name matching this pattern are considered as taking credentials for parameters
 

key_detection_pattern

key_detection_pattern : typing.Pattern[str] = 'BEGIN (.*) PRIVATE KEY'

Regex pattern used to detect the ASCII armor of private keys in string literals
 

suspect_detection_pattern

suspect_detection_pattern : typing.Pattern[str] = 'password'

Objects with identifiers including the pattern are considered suspects for holding credentials