Skip to content

Commit c977fd0

Browse files
Better constant check in java/non-constant-time-crypto-comparison
1 parent d01dc35 commit c977fd0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

java/ql/src/experimental/Security/CWE/CWE-208/NonConstantTimeCryptoComparison.ql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,19 @@ private class UserInputInComparisonConfig extends TaintTracking2::Configuration
142142
}
143143
}
144144

145+
private predicate looksLikeConstant(Expr expr) {
146+
expr.isCompileTimeConstant()
147+
or
148+
expr.(VarAccess).getVariable().isFinal() and expr.getType() instanceof TypeString
149+
}
150+
145151
/**
146152
* A sink that compares input using a non-constant time algorithm.
147153
*/
148154
private class NonConstantTimeComparisonSink extends DataFlow::Node {
149155
Expr anotherParameter;
150156

151157
NonConstantTimeComparisonSink() {
152-
not anotherParameter.isCompileTimeConstant() and
153158
(
154159
exists(NonConstantTimeEqualsCall call |
155160
this.asExpr() = call.getQualifier() and
@@ -167,7 +172,8 @@ private class NonConstantTimeComparisonSink extends DataFlow::Node {
167172
this.asExpr() = call.getArgument(1) and anotherParameter = call.getArgument(0)
168173
)
169174
)
170-
)
175+
) and
176+
not looksLikeConstant(anotherParameter)
171177
}
172178

173179
predicate includesUserInput() {

0 commit comments

Comments
 (0)