1227
Example 1:
This code changes a user's password.
Example Language: PHP (Bad)
$user = $_GET['user'];
$pass = $_GET['pass'];
$checkpass = $_GET['checkpass'];
if ($pass == $checkpass) {
SetUserPassword($user, $pass);
}
While the code confirms that the requesting user typed the same new password twice, it does not
confirm that the user requesting the password change is the same user whose password will be
changed. An attacker can request a change of another user's password and gain control of the
victim's account.
Example 2:
The following code reads a password from a properties file and uses the password to connect to a
database.
Example Language: Java (Bad)
...
Properties prop = new Properties();
prop.load(new FileInputStream("config.properties"));
String password = prop.getProperty("password");
DriverManager.getConnection(url, usr, password);
...
This code will run successfully, but anyone who has access to config.properties can read the value
of password. If a devious employee has access to this information, they can use it to break into the
system.
Example 3:
The following code reads a password from the registry and uses the password to create a new
network credential.
Example Language: Java (Bad)
...
String password = regKey.GetValue(passKey).toString();
NetworkCredential netCred = new NetworkCredential(username,password,domain);
...
This code will run successfully, but anyone who has access to the registry key used to store the
password can read the value of password. If a devious employee has access to this information,
they can use it to break into the system
Example 4:
Both of these examples verify a password by comparing it to a stored compressed version.
Example Language: C (Bad)
int VerifyAdmin(char *password) {
if (strcmp(compress(password), compressed_password)) {
printf("Incorrect Password!\n");
return(0);
}
printf("Entering Diagnostic Mode...\n");
return(1);
CWE Version 4.14
CWE-522: Insufficiently Protected Credentials
CWE-522: Insufficiently Protected Credentials