Skip to content

Commit 1f7990d

Browse files
committed
Refactor to use ConditionalBypassQuery.qll
1 parent a484e9f commit 1f7990d

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Provides classes to be used in queries related to vulnerabilities
3+
* about unstrusted input being used in security decisions.
4+
*/
5+
6+
import java
7+
import semmle.code.java.dataflow.FlowSources
8+
import semmle.code.java.security.SensitiveActions
9+
import semmle.code.java.controlflow.Guards
10+
11+
/**
12+
* Holds if `ma` is controlled by the condition expression `e`.
13+
*/
14+
predicate conditionControlsMethod(MethodAccess ma, Expr e) {
15+
exists(ConditionBlock cb, SensitiveExecutionMethod m, boolean cond |
16+
ma.getMethod() = m and
17+
cb.controls(ma.getBasicBlock(), cond) and
18+
not cb.controls(m.getAReference().getBasicBlock(), cond.booleanNot()) and
19+
e = cb.getCondition()
20+
)
21+
}
22+
23+
/**
24+
* A taint tracking configuration for untrusted data flowing to sensitive conditions.
25+
*/
26+
class ConditionalBypassFlowConfig extends TaintTracking::Configuration {
27+
ConditionalBypassFlowConfig() { this = "ConditionalBypassFlowConfig" }
28+
29+
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
30+
31+
override predicate isSink(DataFlow::Node sink) { conditionControlsMethod(_, sink.asExpr()) }
32+
}

java/ql/src/Security/CWE/CWE-807/ConditionalBypass.ql

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,10 @@
1313
*/
1414

1515
import java
16-
import semmle.code.java.dataflow.FlowSources
17-
import semmle.code.java.security.SensitiveActions
18-
import semmle.code.java.controlflow.Dominance
19-
import semmle.code.java.controlflow.Guards
16+
import semmle.code.java.dataflow.DataFlow
17+
import semmle.code.java.security.ConditionalBypassQuery
2018
import DataFlow::PathGraph
2119

22-
/**
23-
* Calls to a sensitive method that are controlled by a condition
24-
* on the given expression.
25-
*/
26-
predicate conditionControlsMethod(MethodAccess m, Expr e) {
27-
exists(ConditionBlock cb, SensitiveExecutionMethod def, boolean cond |
28-
cb.controls(m.getBasicBlock(), cond) and
29-
def = m.getMethod() and
30-
not cb.controls(def.getAReference().getBasicBlock(), cond.booleanNot()) and
31-
e = cb.getCondition()
32-
)
33-
}
34-
35-
class ConditionalBypassFlowConfig extends TaintTracking::Configuration {
36-
ConditionalBypassFlowConfig() { this = "ConditionalBypassFlowConfig" }
37-
38-
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
39-
40-
override predicate isSink(DataFlow::Node sink) { conditionControlsMethod(_, sink.asExpr()) }
41-
}
42-
4320
from
4421
DataFlow::PathNode source, DataFlow::PathNode sink, MethodAccess m, Expr e,
4522
ConditionalBypassFlowConfig conf

0 commit comments

Comments
 (0)