This is similar to False Negative: Weak Algorithm Spec from Object to be used with Cipher is not reported. The difference is that this False Negative is for MessageDigest
.
package com.minimals.messagedigest.baseCase;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MessageDigestBase {
public static void main(String[] args) {
MessageDigest digest;
String algorithmName = "MD5";
try {
digest = MessageDigest.getInstance(algorithmName);
System.out.println(digest.getAlgorithm());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
}
We scanned the source Java file using the docker. The command we used is:
sonar-scanner \
-Dsonar.projectKey={PROJECT NAME} \
-Dsonar.sources=. \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login={PROJECT KEY}
However, while it is possible to statically compute the value to be passed to MessageDigest.getInstance()
, SonarQube does not report it.
Of course, SonarQube reports the issue when MD5 is used directly, such as:
digest = MessageDigest.getInstance("MD5");
in a similar source file.
Which is why I think it is a false negative.
Additional Details
Language: Java
Rule: java:S4790 Using weak hashing algorithms is security-sensitive
Product Details:
SonarQube Community Edition Version - 9.6.1
Sonar Scanner Version - 4.7
Java Version - Java 11.0.14.1 Eclipse Adoptium (64-bit)
Operating System - MacOS Monterey version 12.6