Skip to content

Commit 7ca57fd

Browse files
authored
Merge pull request #5294 from Marcono1234/patch-1
Java: Fix wrong algorithm name matching
2 parents f3885a8 + d5d0439 commit 7ca57fd

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,16 @@ private string algorithmRegex(string algorithmString) {
120120
* Gets the name of an algorithm that is known to be insecure.
121121
*/
122122
string getAnInsecureAlgorithmName() {
123-
result = "DES" or
124-
result = "RC2" or
125-
result = "RC4" or
126-
result = "RC5" or
127-
result = "ARCFOUR" or // a variant of RC4
128-
result = "ECB" or // encryption mode ECB like AES/ECB/NoPadding is vulnerable to replay and other attacks
129-
result = "AES/CBC/PKCS[5|7]Padding" // CBC mode of operation with PKCS#5 (or PKCS#7) padding is vulnerable to padding oracle attacks
123+
result =
124+
[
125+
"DES", "RC2", "RC4", "RC5",
126+
// ARCFOUR is a variant of RC4
127+
"ARCFOUR",
128+
// Encryption mode ECB like AES/ECB/NoPadding is vulnerable to replay and other attacks
129+
"ECB",
130+
// CBC mode of operation with PKCS#5 or PKCS#7 padding is vulnerable to padding oracle attacks
131+
"AES/CBC/PKCS[57]Padding"
132+
]
130133
}
131134

132135
/**
@@ -163,14 +166,11 @@ string getInsecureAlgorithmRegex() {
163166
* Gets the name of an algorithm that is known to be secure.
164167
*/
165168
string getASecureAlgorithmName() {
166-
result = "RSA" or
167-
result = "SHA256" or
168-
result = "SHA512" or
169-
result = "CCM" or
170-
result = "GCM" or
171-
result = "AES([^a-zA-Z](?!ECB|CBC/PKCS[5|7]Padding)).*" or
172-
result = "Blowfish" or
173-
result = "ECIES"
169+
result =
170+
[
171+
"RSA", "SHA256", "SHA512", "CCM", "GCM", "AES([^a-zA-Z](?!ECB|CBC/PKCS[57]Padding)).*",
172+
"Blowfish", "ECIES"
173+
]
174174
}
175175

176176
private string rankedSecureAlgorithm(int i) { result = rank[i](getASecureAlgorithmName()) }

0 commit comments

Comments
 (0)