Password Plaintext Storage

NVD Categorization

CWE-256: Plaintext Storage of a Password: Storing a password in plaintext may result in a system compromise.

CWE-312: Cleartext Storage of Sensitive Information: The application stores sensitive information in cleartext within a resource that might be accessible to another control sphere.

Description

Storing a password in plaintext may result in a system compromise.

Password management issues occur when a password is stored in plaintext in an application’s properties or configuration file. A programmer can attempt to remedy the password management problem by obscuring the password with an encoding function, such as base 64 encoding, but this effort does not adequately protect the password.

⚠️ Note

Similarly, using fast cryptographic hash functions or lightly modified constructions (for example, chaining SHA-256 and SHA-512) does not adequately protect stored passwords against rainbow table or precomputation attacks. Such approaches remain computationally cheap and can be recomputed by attackers. OWASP recommends using dedicated, memory-hard password hashing functions such as bcrypt, scrypt, or Argon2.

Storing a plaintext password in a configuration file allows anyone who can read the file access to the password-protected resource. Developers sometimes believe that they cannot defend the application from someone who has access to the configuration, but this attitude makes an attacker’s job easier. Good password management guidelines require that a password never be stored in plaintext.

Examples

The following code reads a password from a properties file and uses the password to connect to a database.

    ...
    Properties prop = new Properties();
    prop.load(new FileInputStream("config.properties"));
    String password = prop.getProperty("password");

    DriverManager.getConnection(url, usr, password);
    ...