Hardcoded credentials Critical

Hardcoded credentials can be intercepted by malicious actors. Even after removing them from the code they may still pose a risk because an attacker might have recorded them to use them at a later point in time.

Detector ID
java/hardcoded-credentials@v1.0
Category
Common Weakness Enumeration (CWE) external icon

Noncompliant example

1public void createSqlConnectionNoncompliant() throws Exception {
2    // Noncompliant: password is hardcoded.
3    final Connection connection = DriverManager.getConnection("some url",
4            "username", "password");
5    connection.close();
6}

Compliant example

1public void createSqlConnectionCompliant() throws Exception {
2    // Compliant: password is obtained from environment.
3    final Connection connection = DriverManager.getConnection("some url",
4            "user", System.getProperty("pwd"));
5    connection.close();
6}