Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weak hash and weak random Java rules need to guard from none #426

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion precli/rules/java/stdlib/java_security_weak_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def analyze_method_invocation(self, context: dict, call: Call) -> Result:
argument = call.get_argument(position=0)
algorithm = argument.value_str

if algorithm.upper() not in WEAK_HASHES:
if algorithm is None or algorithm.upper() not in WEAK_HASHES:
return

fixes = Rule.get_fixes(
Expand Down
2 changes: 1 addition & 1 deletion precli/rules/java/stdlib/java_security_weak_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def analyze_method_invocation(self, context: dict, call: Call) -> Result:
argument = call.get_argument(position=0)
algorithm = argument.value_str

if algorithm.upper() != "SHA1PRNG":
if algorithm is None or algorithm.upper() != "SHA1PRNG":
return

fixes = Rule.get_fixes(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// level: NONE
// False negative
import java.security.*;
import java.util.*;


public class MessageDigestMD5 {
public static void main(String[] args) {
try {
Properties hashProps = new Properties();
hashProps.setProperty("hashMd5", "MD5")
String algorithm = hashProps.getProperty("hashMd5", "SHA256");
MessageDigest md = MessageDigest.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
System.err.println("MD5 hashing algorithm not available.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_rule_meta(self):
[
"MessageDigestMD2.java",
"MessageDigestMD5.java",
"MessageDigestMD5Property.java",
"MessageDigestSHA1.java",
"MessageDigestSHA256.java",
]
Expand Down