Skip to content

Commit 459d168

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: weak crypto: do not report weak hash algorithms
1 parent 662a824 commit 459d168

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

java/ql/lib/semmle/code/java/security/Encryption.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,7 @@ string getAnInsecureHashAlgorithmName() {
223223
}
224224

225225
private string rankedInsecureAlgorithm(int i) {
226-
// In this case we know these are being used for encryption, so we want to match
227-
// weak hash algorithms too.
228-
result =
229-
rank[i](string s | s = getAnInsecureAlgorithmName() or s = getAnInsecureHashAlgorithmName())
226+
result = rank[i](string s | s = getAnInsecureAlgorithmName())
230227
}
231228

232229
private string insecureAlgorithmString(int i) {

java/ql/lib/semmle/code/java/security/MaybeBrokenCryptoAlgorithmQuery.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ class InsecureAlgoLiteral extends InsecureAlgorithm, ShortStringLiteral {
3030
s.length() > 1 and
3131
not s.regexpMatch(getSecureAlgorithmRegex()) and
3232
// Exclude results covered by another query.
33-
not s.regexpMatch(getInsecureAlgorithmRegex())
33+
not s.regexpMatch(getInsecureAlgorithmRegex()) and
34+
// Exclude results covered by `InsecureAlgoProperty`.
35+
// This removes duplicates when a string literal is a default value for the property,
36+
// such as "MD5" in the following: `props.getProperty("hashAlg2", "MD5")`.
37+
not exists(InsecureAlgoProperty insecAlgoProp | this = insecAlgoProp.getAnArgument())
3438
)
3539
}
3640

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `java/weak-cryptographic-algorithm` query has been updated to no longer report uses of hash functions such as `MD5` and `SHA1` even if they are known to be weak. These hash algorithms are used very often in non-sensitive contexts, making the query too imprecise in practice. The `java/potentially-weak-cryptographic-algorithm` query has been updated to report these uses instead.
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
#select
22
| Test.java:19:20:19:50 | getInstance(...) | Test.java:19:45:19:49 | "DES" | Test.java:19:45:19:49 | "DES" | Cryptographic algorithm $@ is weak and should not be used. | Test.java:19:45:19:49 | "DES" | DES |
33
| Test.java:42:14:42:38 | getInstance(...) | Test.java:42:33:42:37 | "RC2" | Test.java:42:33:42:37 | "RC2" | Cryptographic algorithm $@ is weak and should not be used. | Test.java:42:33:42:37 | "RC2" | RC2 |
4-
| WeakHashing.java:21:30:21:92 | getInstance(...) | WeakHashing.java:21:86:21:90 | "MD5" : String | WeakHashing.java:21:56:21:91 | getProperty(...) | Cryptographic algorithm $@ is weak and should not be used. | WeakHashing.java:21:86:21:90 | "MD5" | MD5 |
54
edges
6-
| WeakHashing.java:21:86:21:90 | "MD5" : String | WeakHashing.java:21:56:21:91 | getProperty(...) | provenance | MaD:1 |
7-
models
8-
| 1 | Summary: java.util; Properties; true; getProperty; (String,String); ; Argument[1]; ReturnValue; value; manual |
95
nodes
106
| Test.java:19:45:19:49 | "DES" | semmle.label | "DES" |
117
| Test.java:42:33:42:37 | "RC2" | semmle.label | "RC2" |
12-
| WeakHashing.java:21:56:21:91 | getProperty(...) | semmle.label | getProperty(...) |
13-
| WeakHashing.java:21:86:21:90 | "MD5" : String | semmle.label | "MD5" : String |
148
subpaths

0 commit comments

Comments
 (0)