Conversation
| List<String> domainList = Lists.newArrayList(domains); | ||
| Collections.sort(domainList); | ||
| String prefix = domainList.get(0); | ||
| MessageDigest md5 = MessageDigest.getInstance("MD5"); |
There was a problem hiding this comment.
Semgrep identified a blocking 🔴 issue in your code:
Detected MD5 hash algorithm which is considered insecure. MD5 is not collision resistant and is therefore not suitable as a cryptographic signature. Use HMAC instead.
To resolve this comment:
✨ Commit Assistant fix suggestion
| MessageDigest md5 = MessageDigest.getInstance("MD5"); | |
| MessageDigest md5 = MessageDigest.getInstance("SHA-512"); |
View step-by-step instructions
- Replace the use of MD5 with a stronger hash function, such as SHA-256. Update the
getInstancecall to"SHA-256":MessageDigest sha256 = MessageDigest.getInstance("SHA-256");. - Update the variable name
md5tosha256to reflect the new algorithm being used. - Adjust subsequent lines of code that refer to the
MessageDigestinstance to usesha256instead ofmd5.
Alternatively, if you require a cryptographic signature or authentication instead of raw hashing, consider using HMAC with SHA-256. Use Mac and SecretKeySpec classes to construct an HMAC, for example:
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
Mac hmacSha256 = Mac.getInstance("HmacSHA256");
SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA256");
hmacSha256.init(keySpec);
for (String domain : domainList) {
hmacSha256.update(domain.getBytes("UTF-8"));
hmacSha256.update((byte)10);
}
String hashResult = new String(Hex.encodeHex(hmacSha256.doFinal()));Replace secretKey with a suitable secret key for your use case. This ensures the process uses a more secure method suitable for cryptographic purposes.
💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by use-of-md5.
You can view more details about this finding in the Semgrep AppSec Platform.
| List<String> domainList = Lists.newArrayList(domains); | ||
| Collections.sort(domainList); | ||
| String prefix = domainList.get(0); | ||
| MessageDigest md5 = MessageDigest.getInstance("MD5"); |
There was a problem hiding this comment.
Irrelevant issues were spotted - no action required 🧹
The following issues reported by Semgrep on this PR were found to be irrelevant to your project:
Tip
Weak Encryption Mechanism - issue was found to be a false positive.
Mobb recommends to ignore this issue, however fix is available if you think differently.
Justification
The flagged code does not represent an actual vulnerability within the application’s context. This categorization indicates that the issue is either misidentified by the scanner or deemed irrelevant to the application’s functionality.
| } | ||
| HttpServletResponse res = CmsFlexController.getController(getJsp().getRequest()).getTopResponse(); | ||
| res.setContentType("text/comma-separated-values"); | ||
| String filename = "export_users" + new Random().nextInt(1024) + ".csv"; |
There was a problem hiding this comment.
Insecure Randomness fix is ready
This change fixes a medium severity (🟡) Insecure Randomness issue reported by Semgrep.
Issue description
Insecure Randomness refers to the use of insecure or predictable random number generation algorithms, leading to weak cryptographic keys, session tokens, or initialization vectors. This can facilitate brute-force attacks or cryptographic exploits.
Fix instructions
Use secure random number generation algorithms provided by cryptographic libraries or frameworks.
diff --git a/src/CmsUsersCsvDownloadDialog.java b/src/CmsUsersCsvDownloadDialog.java
--- a/src/CmsUsersCsvDownloadDialog.java
+++ b/src/CmsUsersCsvDownloadDialog.java
@@ -52,6 +52,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
+import java.security.SecureRandom;
/**
* Generates a CSV file for a given list.<p>
@@ -192,7 +193,7 @@
}
HttpServletResponse res = CmsFlexController.getController(getJsp().getRequest()).getTopResponse();
res.setContentType("text/comma-separated-values");
- String filename = "export_users" + new Random().nextInt(1024) + ".csv";
+ String filename = "export_users" + new SecureRandom().nextInt(1024) + ".csv";
res.setHeader(
"Content-Disposition",
new StringBuffer("attachment; filename=\"").append(filename).append("\"").toString());
|
New Issues (1)Checkmarx found the following issues in this Pull Request
|


No description provided.