-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathConditionalBypass.ql
More file actions
51 lines (45 loc) · 1.71 KB
/
ConditionalBypass.ql
File metadata and controls
51 lines (45 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* @name User-controlled bypass of sensitive method
* @description User-controlled bypassing of sensitive methods may allow attackers to avoid
* passing through authentication systems.
* @kind path-problem
* @problem.severity error
* @precision medium
* @id java/user-controlled-bypass
* @tags security
* external/cwe/cwe-807
* external/cwe/cwe-290
*/
import java
import semmle.code.java.dataflow.FlowSources
import semmle.code.java.security.SensitiveActions
import semmle.code.java.controlflow.Dominance
import semmle.code.java.controlflow.Guards
import DataFlow::PathGraph
/**
* Calls to a sensitive method that are controlled by a condition
* on the given expression.
*/
predicate conditionControlsMethod(MethodAccess m, Expr e) {
exists(ConditionBlock cb, SensitiveExecutionMethod def, boolean cond |
cb.controls(m.getBasicBlock(), cond) and
def = m.getMethod() and
not cb.controls(def.getAReference().getBasicBlock(), cond.booleanNot()) and
e = cb.getCondition()
)
}
class ConditionalBypassFlowConfig extends TaintTracking::Configuration {
ConditionalBypassFlowConfig() { this = "ConditionalBypassFlowConfig" }
override predicate isSource(DataFlow::Node source) { source instanceof UserInput }
override predicate isSink(DataFlow::Node sink) { conditionControlsMethod(_, sink.asExpr()) }
}
from
DataFlow::PathNode source, DataFlow::PathNode sink, MethodAccess m, Expr e,
ConditionalBypassFlowConfig conf
where
conditionControlsMethod(m, e) and
sink.getNode().asExpr() = e and
conf.hasFlowPath(source, sink)
select m, source, sink,
"Sensitive method may not be executed depending on $@, which flows from $@.", e, "this condition",
source.getNode(), "user input"