Skip to main content

Hardcoded password

Back to rules list


The password configuration to this API appears to be hardcoded. It is suggest to externalized configuration such as password to avoid leakage of secret information.

Risk

The source code or its binary form is more likely to be accessable by an attacker than a production configuration.
To be managed safely, passwords and secret keys should be stored in separate configuration files.

Vulnerable Code

config.setPassword("NotSoSecr3tP@ssword");

Solution

Configuration file :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
    <add key="api_password" value="b3e521073ca276dc2b7caf6247b6ddc72d5e2d2d" />
  </appSettings>
</configuration>
string apiPassword = ConfigurationManager.AppSettings["api_password"];

config.setPassword(apiPassword);

References

CWE-259: Use of Hard-coded Password