CWE-203: Observable Discrepancy

Description:
The product behaves differently or sends different responses under different circumstances in a way that is observable to an unauthorized actor.

Affected languages: Not Language-Specific
Affected technologies: Not Technology-Specific
Parent weaknesses: CWE-200, CWE-200

Consequences:
  - Confidentiality: Read Application Data
  - Confidentiality: Read Application Data

Mitigations:
  - [Architecture and Design] Compartmentalize the system to have "safe" areas where trust boundaries can be unambiguously drawn. Do not allow sensitive data to go outside of the trust boundary and always be careful when interfacing with a compartment outside of the safe area. 
                   Ensure that appropriate compartm
  - [Implementation] Ensure that error messages only contain minimal details that are useful to the intended audience and no one else. The messages need to strike the balance between being too cryptic (which can confuse users) or being too detailed (which may reveal more than intended). The messages should not reveal th

Demonstrative examples:
The following code checks validity of the supplied username and password and notifies the user of a successful or failed login.
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.
my $username=param('username');
                   my $password=param('password');
                   
                   if (IsValidUsername($username) == 1)
                   {
  

In this example, the attacker observes how long an authentication takes when the user types in the correct password.
When the attacker tries their own values, they can first try strings of various length. When they find a string of the right length, the computation will take a bit longer, because the for loop will run at least once. Additionally, with this code, the attacker can possibly learn one character of the password at a time, because when they guess the first character right, the computation will take longer than a wrong guesses. Such an attack can break even the most sophisticated password with a few hundred guesses.
def validate_password(actual_pw, typed_pw):
		  
                    if len(actual_pw) <> len(typed_pw):
		    return 0 
                    for i in len(actual_pw):


Real-world examples:
  - CVE-2020-8695: Observable discrepancy in the RAPL interface for some Intel processors allows information disclosure.
  - CVE-2019-14353: Crypto hardware wallet's power consumption relates to total number of pixels illuminated, creating a side channel in the USB connection that allows attackers to determine secrets displayed such as PIN
  - CVE-2019-10071: Java-oriented framework compares HMAC signatures  using  String.equals() instead of a constant-time algorithm, causing timing discrepancies
  - CVE-2002-2094: This, and others, use ".." attacks and monitor error responses, so there is overlap with directory traversal.
  - CVE-2001-1483: Enumeration of valid usernames based on inconsistent responses