Skip to content

Commit 7445fc4

Browse files
committed
Ruby: configsig rb/regexp-injection
1 parent 494b7b3 commit 7445fc4

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

ruby/ql/lib/codeql/ruby/security/regexp/RegExpInjectionQuery.qll

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
22
* Provides a taint-tracking configuration for detecting regexp injection vulnerabilities.
33
*
4-
* Note, for performance reasons: only import this file if `Configuration` is needed,
5-
* otherwise `RegExpInjectionCustomizations` should be imported instead.
4+
* Note, for performance reasons: only import this file if
5+
* `RegExpInjectionFlow` is needed, otherwise
6+
* `RegExpInjectionCustomizations` should be imported instead.
67
*/
78

89
import codeql.ruby.DataFlow
@@ -12,8 +13,9 @@ import codeql.ruby.dataflow.BarrierGuards
1213

1314
/**
1415
* A taint-tracking configuration for detecting regexp injection vulnerabilities.
16+
* DEPRECATED: Use `RegExpInjectionFlow`
1517
*/
16-
class Configuration extends TaintTracking::Configuration {
18+
deprecated class Configuration extends TaintTracking::Configuration {
1719
Configuration() { this = "RegExpInjection" }
1820

1921
override predicate isSource(DataFlow::Node source) { source instanceof RegExpInjection::Source }
@@ -26,3 +28,16 @@ class Configuration extends TaintTracking::Configuration {
2628

2729
override predicate isSanitizer(DataFlow::Node node) { node instanceof RegExpInjection::Sanitizer }
2830
}
31+
32+
private module RegExpInjectionConfig implements DataFlow::ConfigSig {
33+
predicate isSource(DataFlow::Node source) { source instanceof RegExpInjection::Source }
34+
35+
predicate isSink(DataFlow::Node sink) { sink instanceof RegExpInjection::Sink }
36+
37+
predicate isBarrier(DataFlow::Node node) { node instanceof RegExpInjection::Sanitizer }
38+
}
39+
40+
/**
41+
* Taint-tracking for detecting regexp injection vulnerabilities.
42+
*/
43+
module RegExpInjectionFlow = TaintTracking::Global<RegExpInjectionConfig>;

ruby/ql/src/queries/security/cwe-1333/RegExpInjection.ql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
* external/cwe/cwe-400
1616
*/
1717

18-
import codeql.ruby.AST
19-
import DataFlow::PathGraph
20-
import codeql.ruby.DataFlow
2118
import codeql.ruby.security.regexp.RegExpInjectionQuery
19+
import RegExpInjectionFlow::PathGraph
2220

23-
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
24-
where cfg.hasFlowPath(source, sink)
21+
from RegExpInjectionFlow::PathNode source, RegExpInjectionFlow::PathNode sink
22+
where RegExpInjectionFlow::flowPath(source, sink)
2523
select sink.getNode(), source, sink, "This regular expression depends on a $@.", source.getNode(),
2624
"user-provided value"

0 commit comments

Comments
 (0)