Ruby: configsig rb/regexp-injection

This commit is contained in:
Alex Ford
2023-09-03 16:14:39 +01:00
parent 494b7b3fdf
commit 7445fc43f9
2 changed files with 21 additions and 8 deletions

View File

@@ -1,8 +1,9 @@
/**
* Provides a taint-tracking configuration for detecting regexp injection vulnerabilities.
*
* Note, for performance reasons: only import this file if `Configuration` is needed,
* otherwise `RegExpInjectionCustomizations` should be imported instead.
* Note, for performance reasons: only import this file if
* `RegExpInjectionFlow` is needed, otherwise
* `RegExpInjectionCustomizations` should be imported instead.
*/
import codeql.ruby.DataFlow
@@ -12,8 +13,9 @@ import codeql.ruby.dataflow.BarrierGuards
/**
* A taint-tracking configuration for detecting regexp injection vulnerabilities.
* DEPRECATED: Use `RegExpInjectionFlow`
*/
class Configuration extends TaintTracking::Configuration {
deprecated class Configuration extends TaintTracking::Configuration {
Configuration() { this = "RegExpInjection" }
override predicate isSource(DataFlow::Node source) { source instanceof RegExpInjection::Source }
@@ -26,3 +28,16 @@ class Configuration extends TaintTracking::Configuration {
override predicate isSanitizer(DataFlow::Node node) { node instanceof RegExpInjection::Sanitizer }
}
private module RegExpInjectionConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { source instanceof RegExpInjection::Source }
predicate isSink(DataFlow::Node sink) { sink instanceof RegExpInjection::Sink }
predicate isBarrier(DataFlow::Node node) { node instanceof RegExpInjection::Sanitizer }
}
/**
* Taint-tracking for detecting regexp injection vulnerabilities.
*/
module RegExpInjectionFlow = TaintTracking::Global<RegExpInjectionConfig>;

View File

@@ -15,12 +15,10 @@
* external/cwe/cwe-400
*/
import codeql.ruby.AST
import DataFlow::PathGraph
import codeql.ruby.DataFlow
import codeql.ruby.security.regexp.RegExpInjectionQuery
import RegExpInjectionFlow::PathGraph
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
where cfg.hasFlowPath(source, sink)
from RegExpInjectionFlow::PathNode source, RegExpInjectionFlow::PathNode sink
where RegExpInjectionFlow::flowPath(source, sink)
select sink.getNode(), source, sink, "This regular expression depends on a $@.", source.getNode(),
"user-provided value"