Skip to content

Commit 51e2a54

Browse files
committed
Java: move EncryptedSensitiveMethodCall into Sanitizers.qll
Address review feedback by moving the shared method-name-based encryption/hash/digest check into Sanitizers.qll, and reference it from both CleartextStorageQuery.qll and SensitiveLoggingQuery.qll instead of duplicating the definition.
1 parent 75162bb commit 51e2a54

3 files changed

Lines changed: 13 additions & 17 deletions

File tree

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java
44
private import semmle.code.java.dataflow.TaintTracking
5+
private import semmle.code.java.security.Sanitizers
56
private import semmle.code.java.security.SensitiveActions
67

78
/** A sink representing persistent storage that saves data in clear text. */
@@ -76,17 +77,6 @@ private class DefaultCleartextStorageSanitizer extends CleartextStorageSanitizer
7677
}
7778
}
7879

79-
/**
80-
* Method call for encrypting sensitive information. As there are various implementations of
81-
* encryption (reversible and non-reversible) from both JDK and third parties, this class simply
82-
* checks method name to take a best guess to reduce false positives.
83-
*/
84-
private class EncryptedSensitiveMethodCall extends MethodCall {
85-
EncryptedSensitiveMethodCall() {
86-
this.getMethod().getName().toLowerCase().matches(["%encrypt%", "%hash%", "%digest%"])
87-
}
88-
}
89-
9080
/** Flow configuration for encryption methods flowing to inputs of persistent storage. */
9181
private module EncryptedValueFlowConfig implements DataFlow::ConfigSig {
9282
predicate isSource(DataFlow::Node src) { src.asExpr() instanceof EncryptedSensitiveMethodCall }

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,14 @@ class RegexpCheckBarrier extends DataFlow::Node {
6363
exists(RegexMatch rm | rm instanceof Annotation | this.asExpr() = rm.getString())
6464
}
6565
}
66+
67+
/**
68+
* A method call for encrypting, hashing, or digesting sensitive information. As there are various
69+
* implementations of encryption (reversible and non-reversible) from both JDK and third parties,
70+
* this class simply checks the method name to take a best guess to reduce false positives.
71+
*/
72+
class EncryptedSensitiveMethodCall extends MethodCall {
73+
EncryptedSensitiveMethodCall() {
74+
this.getMethod().getName().toLowerCase().matches(["%encrypt%", "%hash%", "%digest%"])
75+
}
76+
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,7 @@ private class DefaultSensitiveLoggerBarrier extends SensitiveLoggerBarrier {
125125
* This is consistent with the treatment of encryption in `CleartextStorageQuery.qll` (CWE-312).
126126
*/
127127
private class EncryptionBarrier extends SensitiveLoggerBarrier {
128-
EncryptionBarrier() {
129-
exists(MethodCall mc |
130-
this.asExpr() = mc and
131-
mc.getMethod().getName().toLowerCase().matches(["%encrypt%", "%hash%", "%digest%"])
132-
)
133-
}
128+
EncryptionBarrier() { this.asExpr() instanceof EncryptedSensitiveMethodCall }
134129
}
135130

136131
/** A data-flow configuration for identifying potentially-sensitive data flowing to a log output. */

0 commit comments

Comments
 (0)