Skip to content

Commit 713e19f

Browse files
committed
Make non-path query for encryption only
1 parent f34a625 commit 713e19f

File tree

6 files changed

+216
-446
lines changed

6 files changed

+216
-446
lines changed

go/ql/lib/semmle/go/security/BrokenCryptoAlgorithmCustomizations.qll

Lines changed: 0 additions & 58 deletions
This file was deleted.

go/ql/lib/semmle/go/security/BrokenCryptoAlgorithmQuery.qll

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
/**
22
* @name Use of a broken or weak cryptographic algorithm
33
* @description Using broken or weak cryptographic algorithms can compromise security.
4-
* @kind path-problem
4+
* @kind problem
55
* @problem.severity warning
66
* @security-severity 7.5
77
* @precision high
8-
* @id go/weak-crypto-algorithm
8+
* @id go/weak-cryptographic-algorithm
99
* @tags security
1010
* external/cwe/cwe-327
1111
* external/cwe/cwe-328
1212
*/
1313

1414
import go
15-
import semmle.go.security.BrokenCryptoAlgorithmQuery
16-
import BrokenCryptoAlgorithmFlow::PathGraph
1715

18-
from BrokenCryptoAlgorithmFlow::PathNode source, BrokenCryptoAlgorithmFlow::PathNode sink
19-
where BrokenCryptoAlgorithmFlow::flowPath(source, sink)
20-
select sink.getNode(), source, sink, "$@ is used in a weak cryptographic algorithm.",
21-
source.getNode(), "Sensitive data"
16+
from Cryptography::CryptographicOperation operation, string msgPrefix, DataFlow::Node init
17+
where
18+
init = operation.getInitialization() and
19+
// `init` may be a `BlockModeInit`, a `EncryptionAlgorithmInit`, or `operation` itself.
20+
(
21+
not init instanceof BlockModeInit and
22+
exists(Cryptography::CryptographicAlgorithm algorithm |
23+
algorithm = operation.getAlgorithm() and
24+
algorithm.isWeak() and
25+
msgPrefix = "The cryptographic algorithm " + algorithm.getName() and
26+
not algorithm instanceof Cryptography::HashingAlgorithm
27+
)
28+
or
29+
not init instanceof EncryptionAlgorithmInit and
30+
operation.getBlockMode().isWeak() and
31+
msgPrefix = "The block mode " + operation.getBlockMode()
32+
)
33+
select operation, "$@ is broken or weak, and should not be used.", init, msgPrefix

0 commit comments

Comments
 (0)