@@ -8,8 +8,20 @@ private import codeql.ruby.controlflow.CfgNodes
8
8
private import codeql.ruby.DataFlow
9
9
private import codeql.ruby.dataflow.RemoteFlowSources
10
10
private import codeql.ruby.ApiGraphs
11
- private import codeql.ruby.frameworks.ActionView
12
11
private import codeql.ruby.frameworks.ActionDispatch
12
+ private import codeql.ruby.frameworks.ActionView
13
+ private import codeql.ruby.frameworks.Rails
14
+ private import codeql.ruby.frameworks.internal.Rails
15
+
16
+ /**
17
+ * DEPRECATED: Import `codeql.ruby.frameworks.Rails` and use `Rails::ParamsCall` instead.
18
+ */
19
+ deprecated class ParamsCall = Rails:: ParamsCall ;
20
+
21
+ /**
22
+ * DEPRECATED: Import `codeql.ruby.frameworks.Rails` and use `Rails::CookiesCall` instead.
23
+ */
24
+ deprecated class CookiesCall = Rails:: CookiesCall ;
13
25
14
26
/**
15
27
* A `ClassDeclaration` for a class that extends `ActionController::Base`.
@@ -72,7 +84,7 @@ class ActionControllerActionMethod extends Method, Http::Server::RequestHandler:
72
84
override string getFramework ( ) { result = "ActionController" }
73
85
74
86
/** Gets a call to render from within this method. */
75
- RenderCall getARenderCall ( ) { result .getParent + ( ) = this }
87
+ Rails :: RenderCall getARenderCall ( ) { result .getParent + ( ) = this }
76
88
77
89
/**
78
90
* Gets the controller class containing this method.
@@ -119,62 +131,59 @@ private class ActionControllerContextCall extends MethodCall {
119
131
ActionControllerControllerClass getControllerClass ( ) { result = controllerClass }
120
132
}
121
133
122
- /**
123
- * A call to the `params` method to fetch the request parameters.
124
- */
125
- abstract class ParamsCall extends MethodCall {
126
- ParamsCall ( ) { this .getMethodName ( ) = "params" }
127
- }
128
-
129
134
/**
130
135
* A `RemoteFlowSource::Range` to represent accessing the
131
136
* ActionController parameters available via the `params` method.
132
137
*/
133
138
class ParamsSource extends Http:: Server:: RequestInputAccess:: Range {
134
- ParamsSource ( ) { this .asExpr ( ) .getExpr ( ) instanceof ParamsCall }
139
+ ParamsSource ( ) { this .asExpr ( ) .getExpr ( ) instanceof Rails :: ParamsCall }
135
140
136
141
override string getSourceType ( ) { result = "ActionController::Metal#params" }
137
142
}
138
143
139
- /**
140
- * A call to the `cookies` method to fetch the request parameters.
141
- */
142
- abstract class CookiesCall extends MethodCall {
143
- CookiesCall ( ) { this .getMethodName ( ) = "cookies" }
144
- }
145
-
146
144
/**
147
145
* A `RemoteFlowSource::Range` to represent accessing the
148
146
* ActionController parameters available via the `cookies` method.
149
147
*/
150
148
class CookiesSource extends Http:: Server:: RequestInputAccess:: Range {
151
- CookiesSource ( ) { this .asExpr ( ) .getExpr ( ) instanceof CookiesCall }
149
+ CookiesSource ( ) { this .asExpr ( ) .getExpr ( ) instanceof Rails :: CookiesCall }
152
150
153
151
override string getSourceType ( ) { result = "ActionController::Metal#cookies" }
154
152
}
155
153
156
154
/** A call to `cookies` from within a controller. */
157
- private class ActionControllerCookiesCall extends ActionControllerContextCall , CookiesCall { }
155
+ private class ActionControllerCookiesCall extends ActionControllerContextCall , CookiesCallImpl {
156
+ ActionControllerCookiesCall ( ) { this .getMethodName ( ) = "cookies" }
157
+ }
158
158
159
159
/** A call to `params` from within a controller. */
160
- private class ActionControllerParamsCall extends ActionControllerContextCall , ParamsCall { }
160
+ private class ActionControllerParamsCall extends ActionControllerContextCall , ParamsCallImpl {
161
+ ActionControllerParamsCall ( ) { this .getMethodName ( ) = "params" }
162
+ }
161
163
162
164
/** A call to `render` from within a controller. */
163
- private class ActionControllerRenderCall extends ActionControllerContextCall , RenderCall { }
165
+ private class ActionControllerRenderCall extends ActionControllerContextCall , RenderCallImpl {
166
+ ActionControllerRenderCall ( ) { this .getMethodName ( ) = "render" }
167
+ }
164
168
165
169
/** A call to `render_to` from within a controller. */
166
- private class ActionControllerRenderToCall extends ActionControllerContextCall , RenderToCall { }
170
+ private class ActionControllerRenderToCall extends ActionControllerContextCall , RenderToCallImpl {
171
+ ActionControllerRenderToCall ( ) { this .getMethodName ( ) = [ "render_to_body" , "render_to_string" ] }
172
+ }
167
173
168
174
/** A call to `html_safe` from within a controller. */
169
- private class ActionControllerHtmlSafeCall extends HtmlSafeCall {
175
+ private class ActionControllerHtmlSafeCall extends HtmlSafeCallImpl {
170
176
ActionControllerHtmlSafeCall ( ) {
177
+ this .getMethodName ( ) = "html_safe" and
171
178
this .getEnclosingModule ( ) instanceof ActionControllerControllerClass
172
179
}
173
180
}
174
181
175
182
/** A call to `html_escape` from within a controller. */
176
- private class ActionControllerHtmlEscapeCall extends HtmlEscapeCall {
183
+ private class ActionControllerHtmlEscapeCall extends HtmlEscapeCallImpl {
177
184
ActionControllerHtmlEscapeCall ( ) {
185
+ // "h" is aliased to "html_escape" in ActiveSupport
186
+ this .getMethodName ( ) = [ "html_escape" , "html_escape_once" , "h" , "sanitize" ] and
178
187
this .getEnclosingModule ( ) instanceof ActionControllerControllerClass
179
188
}
180
189
}
@@ -291,7 +300,7 @@ ActionControllerControllerClass getAssociatedControllerClass(ErbFile f) {
291
300
// template file, `fp`. In this case, `f` inherits the associated
292
301
// controller classes from `fp`.
293
302
f .isPartial ( ) and
294
- exists ( RenderCall r , ErbFile fp |
303
+ exists ( Rails :: RenderCall r , ErbFile fp |
295
304
r .getLocation ( ) .getFile ( ) = fp and
296
305
r .getTemplateFile ( ) = f and
297
306
result = getAssociatedControllerClass ( fp )
0 commit comments