Skip to content

Commit d46564c

Browse files
committed
Ruby: treat ActionController#cookies as a remote flow source
1 parent f6a8b9a commit d46564c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

ruby/ql/lib/codeql/ruby/frameworks/ActionController.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,28 @@ class ParamsSource extends RemoteFlowSource::Range {
118118
override string getSourceType() { result = "ActionController::Metal#params" }
119119
}
120120

121+
/**
122+
* A call to the `cookies` method to fetch the request parameters.
123+
*/
124+
abstract class CookiesCall extends MethodCall {
125+
CookiesCall() { this.getMethodName() = "cookies" }
126+
}
127+
128+
/**
129+
* A `RemoteFlowSource::Range` to represent accessing the
130+
* ActionController parameters available via the `cookies` method.
131+
*/
132+
class CookiesSource extends RemoteFlowSource::Range {
133+
CookiesCall call;
134+
135+
CookiesSource() { this.asExpr().getExpr() = call }
136+
137+
override string getSourceType() { result = "ActionController::Metal#cookies" }
138+
}
139+
140+
// A call to `cookies` from within a controller.
141+
private class ActionControllerCookiesCall extends ActionControllerContextCall, CookiesCall { }
142+
121143
// A call to `params` from within a controller.
122144
private class ActionControllerParamsCall extends ActionControllerContextCall, ParamsCall { }
123145

ruby/ql/test/library-tests/frameworks/ActionController.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ paramsSources
4949
| app/controllers/foo/bars_controller.rb:21:21:21:26 | call to params |
5050
| app/controllers/foo/bars_controller.rb:22:10:22:15 | call to params |
5151
| app/views/foo/bars/show.html.erb:5:9:5:14 | call to params |
52+
cookiesCalls
53+
| app/controllers/foo/bars_controller.rb:10:27:10:33 | call to cookies |
54+
cookiesSources
55+
| app/controllers/foo/bars_controller.rb:10:27:10:33 | call to cookies |
5256
redirectToCalls
5357
| app/controllers/foo/bars_controller.rb:17:5:17:30 | call to redirect_to |
5458
actionControllerHelperMethods

ruby/ql/test/library-tests/frameworks/ActionController.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ query predicate paramsCalls(ParamsCall c) { any() }
1010

1111
query predicate paramsSources(ParamsSource src) { any() }
1212

13+
query predicate cookiesCalls(CookiesCall c) { any() }
14+
15+
query predicate cookiesSources(CookiesSource src) { any() }
16+
1317
query predicate redirectToCalls(RedirectToCall c) { any() }
1418

1519
query predicate actionControllerHelperMethods(ActionControllerHelperMethod m) { any() }

0 commit comments

Comments
 (0)