Java


JAVA.HARDCODED.PASSWD.FILE : Password in Property File (Java)

Summary

A password is retrieved from a property file.

Password manipulation can be risky, for instance if passwords are stored in plain in a property file. Moreover, passwords stored as program constants expose to the risk of inferring the password by simply looking at the binary executable of the code. This checker identifies situations when password manipulation is done in an unsafe way.

Properties

Class Name Password in Property File (Java)
Significance security
Mnemonic JAVA.HARDCODED.PASSWD.FILE
Categories
CWE CWE:522 Insufficiently Protected Credentials
OWASP-2017 OWASP-2017:A2 Broken authentication
OWASP-2021 OWASP-2021:A7 Identification and authorization failures
Availability Available for Java only.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Password in Property File (Java)"

Example

import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class Passwords {
  private final static String pwd = "password";

  public void test(Properties props) throws SQLException {
      String s = "password";

      props.getProperty("password");                                   // Password in Property File (Java) warning issued here
      props.getProperty(pwd);                                          // Password in Property File (Java) warning issued here
      props.getProperty(s);                                            // Password in Property File (Java) warning issued here
      props.getProperty("www.juliasoft.password");                     // Password in Property File (Java) warning issued here
      props.getProperty("password", "default");                        // Password in Property File (Java) warning issued here
      props.getProperty("www.juliasoft.password", "default");          // Password in Property File (Java) warning issued here
      props.setProperty("com.julia.password", "goofy mouse");          // Hardcoded Password (Java) warning issued here
      props.setProperty("com.julia.password", s);                      // Hardcoded Password (Java) warning issued here
      props.setProperty("com.julia.password", s + " and " + pwd);
      DriverManager.getConnection("www.juliasoft.com", "silvio", pwd); // Hardcoded Password (Java) warning issued here
    }
}

Resolution

Avoid storing passwords in property files and use encrypted files instead. Do not use program constants for passwords, store them in encrypted files instead.

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.