Skip to content

Commit f24102e

Browse files
committed
Ruby: configsig rb/weak-params
1 parent 6c06def commit f24102e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

ruby/ql/src/experimental/weak-params/WeakParams.ql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import codeql.ruby.Concepts
1515
import codeql.ruby.DataFlow
1616
import codeql.ruby.TaintTracking
1717
import codeql.ruby.frameworks.ActionController
18-
import DataFlow::PathGraph
1918

2019
/**
2120
* Gets a call to `request` in an ActionController controller class.
@@ -42,16 +41,18 @@ class WeakParams extends DataFlow::CallNode {
4241
* A Taint tracking config where the source is a weak params access in a controller and the sink
4342
* is a method call of a model class
4443
*/
45-
class Configuration extends TaintTracking::Configuration {
46-
Configuration() { this = "WeakParamsConfiguration" }
47-
48-
override predicate isSource(DataFlow::Node node) { node instanceof WeakParams }
44+
private module WeakParamsConfig implements DataFlow::ConfigSig {
45+
predicate isSource(DataFlow::Node node) { node instanceof WeakParams }
4946

5047
// the sink is an instance of a Model class that receives a method call
51-
override predicate isSink(DataFlow::Node node) { node = any(PersistentWriteAccess a).getValue() }
48+
predicate isSink(DataFlow::Node node) { node = any(PersistentWriteAccess a).getValue() }
5249
}
5350

54-
from Configuration config, DataFlow::PathNode source, DataFlow::PathNode sink
55-
where config.hasFlowPath(source, sink)
51+
private module WeakParamsFlow = TaintTracking::Global<WeakParamsConfig>;
52+
53+
private import WeakParamsFlow::PathGraph
54+
55+
from WeakParamsFlow::PathNode source, WeakParamsFlow::PathNode sink
56+
where WeakParamsFlow::flowPath(source, sink)
5657
select sink.getNode(), source, sink,
5758
"By exposing all keys in request parameters or by blindy accessing them, unintended parameters could be used and lead to mass-assignment or have other unexpected side-effects. It is safer to follow the 'strong parameters' pattern in Rails, which is outlined here: https://api.rubyonrails.org/classes/ActionController/StrongParameters.html"

0 commit comments

Comments
 (0)