Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f760baa

Browse files
committed
Ruby: configsig rb/user-controlled-bypass
1 parent f56c071 commit f760baa

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

ruby/ql/lib/codeql/ruby/security/ConditionalBypassQuery.qll

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Provides a taint tracking configuration for reasoning about bypass of sensitive action guards.
33
*
44
* Note, for performance reasons: only import this file if
5-
* `ConditionalBypass::Configuration` is needed, otherwise
5+
* `ConditionalBypassFlow` is needed, otherwise
66
* `ConditionalBypassCustomizations` should be imported instead.
77
*/
88

@@ -13,8 +13,9 @@ import ConditionalBypassCustomizations::ConditionalBypass
1313

1414
/**
1515
* A taint tracking configuration for bypass of sensitive action guards.
16+
* DEPRECATED: Use `ConditionalBypassFlow` instead
1617
*/
17-
class Configuration extends TaintTracking::Configuration {
18+
deprecated class Configuration extends TaintTracking::Configuration {
1819
Configuration() { this = "ConditionalBypass" }
1920

2021
override predicate isSource(DataFlow::Node source) { source instanceof Source }
@@ -26,3 +27,16 @@ class Configuration extends TaintTracking::Configuration {
2627
node instanceof Sanitizer
2728
}
2829
}
30+
31+
private module Config implements DataFlow::ConfigSig {
32+
predicate isSource(DataFlow::Node source) { source instanceof Source }
33+
34+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
35+
36+
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
37+
}
38+
39+
/**
40+
* Taint-tracking for bypass of sensitive action guards.
41+
*/
42+
module ConditionalBypassFlow = TaintTracking::Global<Config>;

ruby/ql/src/experimental/cwe-807/ConditionalBypass.ql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import codeql.ruby.DataFlow
1717
import codeql.ruby.dataflow.internal.DataFlowPublic
1818
import codeql.ruby.security.ConditionalBypassQuery
1919
import codeql.ruby.security.SensitiveActions
20-
import DataFlow::PathGraph
20+
import ConditionalBypassFlow::PathGraph
2121

2222
/**
2323
* Holds if the value of `nd` flows into `guard`.
@@ -69,15 +69,18 @@ class SensitiveActionGuardComparisonOperand extends Sink {
6969
* control if `action` should be executed or not.
7070
*/
7171
predicate isTaintedGuardForSensitiveAction(
72-
DataFlow::PathNode sink, DataFlow::PathNode source, SensitiveAction action
72+
ConditionalBypassFlow::PathNode sink, ConditionalBypassFlow::PathNode source,
73+
SensitiveAction action
7374
) {
7475
action = sink.getNode().(Sink).getAction() and
7576
// exclude the intermediary sink
7677
not sink.getNode() instanceof SensitiveActionGuardComparisonOperand and
77-
exists(Configuration cfg | cfg.hasFlowPath(source, sink))
78+
ConditionalBypassFlow::flowPath(source, sink)
7879
}
7980

80-
from DataFlow::PathNode source, DataFlow::PathNode sink, SensitiveAction action
81+
from
82+
ConditionalBypassFlow::PathNode source, ConditionalBypassFlow::PathNode sink,
83+
SensitiveAction action
8184
where isTaintedGuardForSensitiveAction(sink, source, action)
8285
select sink.getNode(), source, sink, "This condition guards a sensitive $@, but a $@ controls it.",
8386
action, "action", source.getNode(), "user-provided value"

0 commit comments

Comments
 (0)