Skip to content

Commit 5fd3594

Browse files
committed
Python: Move TimingAttack.qll to new dataflow API
1 parent 5d8329d commit 5fd3594

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

python/ql/src/experimental/semmle/python/security/TimingAttack.qll

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ class NonConstantTimeComparisonSink extends DataFlow::Node {
164164

165165
/** Holds if remote user input was used in the comparison. */
166166
predicate includesUserInput() {
167-
exists(UserInputInComparisonConfig config |
168-
config.hasFlowTo(DataFlow2::exprNode(anotherParameter))
169-
)
167+
UserInputInComparisonFlow::flowTo(DataFlow2::exprNode(anotherParameter))
170168
}
171169
}
172170

@@ -177,9 +175,7 @@ class SecretSource extends DataFlow::Node {
177175
SecretSource() { secret = this.asExpr() }
178176

179177
/** Holds if the secret was deliverd by remote user. */
180-
predicate includesUserInput() {
181-
exists(UserInputSecretConfig config | config.hasFlowTo(DataFlow2::exprNode(secret)))
182-
}
178+
predicate includesUserInput() { UserInputSecretFlow::flowTo(DataFlow2::exprNode(secret)) }
183179
}
184180

185181
/** A string for `match` that identifies strings that look like they represent secret data. */
@@ -267,23 +263,21 @@ private string sensitiveheaders() {
267263
/**
268264
* A config that tracks data flow from remote user input to Variable that hold sensitive info
269265
*/
270-
class UserInputSecretConfig extends TaintTracking::Configuration {
271-
UserInputSecretConfig() { this = "UserInputSecretConfig" }
266+
module UserInputSecretConfig implements DataFlow::ConfigSig {
267+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
272268

273-
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
274-
275-
override predicate isSink(DataFlow::Node sink) { sink.asExpr() instanceof CredentialExpr }
269+
predicate isSink(DataFlow::Node sink) { sink.asExpr() instanceof CredentialExpr }
276270
}
277271

272+
module UserInputSecretFlow = TaintTracking::Global<UserInputSecretConfig>;
273+
278274
/**
279275
* A config that tracks data flow from remote user input to Equality test
280276
*/
281-
class UserInputInComparisonConfig extends TaintTracking2::Configuration {
282-
UserInputInComparisonConfig() { this = "UserInputInComparisonConfig" }
277+
module UserInputInComparisonConfig implements DataFlow::ConfigSig {
278+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
283279

284-
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
285-
286-
override predicate isSink(DataFlow::Node sink) {
280+
predicate isSink(DataFlow::Node sink) {
287281
exists(Compare cmp, Expr left, Expr right, Cmpop cmpop |
288282
cmpop.getSymbol() = ["==", "in", "is not", "!="] and
289283
cmp.compares(left, cmpop, right) and
@@ -292,22 +286,24 @@ class UserInputInComparisonConfig extends TaintTracking2::Configuration {
292286
}
293287
}
294288

289+
module UserInputInComparisonFlow = TaintTracking::Global<UserInputInComparisonConfig>;
290+
295291
/**
296292
* A configuration tracing flow from a client Secret obtained by an HTTP header to a len() function.
297293
*/
298-
private class ExcludeLenFunc extends TaintTracking2::Configuration {
299-
ExcludeLenFunc() { this = "ExcludeLenFunc" }
300-
301-
override predicate isSource(DataFlow::Node source) { source instanceof ClientSuppliedSecret }
294+
private module ExcludeLenFuncConfig implements DataFlow::ConfigSig {
295+
predicate isSource(DataFlow::Node source) { source instanceof ClientSuppliedSecret }
302296

303-
override predicate isSink(DataFlow::Node sink) {
297+
predicate isSink(DataFlow::Node sink) {
304298
exists(Call call |
305299
call.getFunc().(Name).getId() = "len" and
306300
sink.asExpr() = call.getArg(0)
307301
)
308302
}
309303
}
310304

305+
module ExcludeLenFuncFlow = TaintTracking::Global<ExcludeLenFuncConfig>;
306+
311307
/**
312308
* Holds if there is a fast-fail check.
313309
*/
@@ -343,8 +339,7 @@ class CompareSink extends DataFlow::Node {
343339
* Holds if there is a flow to len().
344340
*/
345341
predicate flowtolen() {
346-
exists(ExcludeLenFunc config, DataFlow2::PathNode source, DataFlow2::PathNode sink |
347-
config.hasFlowPath(source, sink)
348-
)
342+
// TODO: Fly by comment: I don't understand this code at all, seems very strange.
343+
ExcludeLenFuncFlow::flowPath(_, _)
349344
}
350345
}

0 commit comments

Comments
 (0)