@@ -8,8 +8,20 @@ private import codeql.ruby.controlflow.CfgNodes
88private import codeql.ruby.DataFlow
99private import codeql.ruby.dataflow.RemoteFlowSources
1010private import codeql.ruby.ApiGraphs
11- private import codeql.ruby.frameworks.ActionView
1211private 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 ;
1325
1426/**
1527 * A `ClassDeclaration` for a class that extends `ActionController::Base`.
@@ -72,7 +84,7 @@ class ActionControllerActionMethod extends Method, Http::Server::RequestHandler:
7284 override string getFramework ( ) { result = "ActionController" }
7385
7486 /** Gets a call to render from within this method. */
75- RenderCall getARenderCall ( ) { result .getParent + ( ) = this }
87+ Rails :: RenderCall getARenderCall ( ) { result .getParent + ( ) = this }
7688
7789 /**
7890 * Gets the controller class containing this method.
@@ -119,62 +131,59 @@ private class ActionControllerContextCall extends MethodCall {
119131 ActionControllerControllerClass getControllerClass ( ) { result = controllerClass }
120132}
121133
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-
129134/**
130135 * A `RemoteFlowSource::Range` to represent accessing the
131136 * ActionController parameters available via the `params` method.
132137 */
133138class ParamsSource extends Http:: Server:: RequestInputAccess:: Range {
134- ParamsSource ( ) { this .asExpr ( ) .getExpr ( ) instanceof ParamsCall }
139+ ParamsSource ( ) { this .asExpr ( ) .getExpr ( ) instanceof Rails :: ParamsCall }
135140
136141 override string getSourceType ( ) { result = "ActionController::Metal#params" }
137142}
138143
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-
146144/**
147145 * A `RemoteFlowSource::Range` to represent accessing the
148146 * ActionController parameters available via the `cookies` method.
149147 */
150148class CookiesSource extends Http:: Server:: RequestInputAccess:: Range {
151- CookiesSource ( ) { this .asExpr ( ) .getExpr ( ) instanceof CookiesCall }
149+ CookiesSource ( ) { this .asExpr ( ) .getExpr ( ) instanceof Rails :: CookiesCall }
152150
153151 override string getSourceType ( ) { result = "ActionController::Metal#cookies" }
154152}
155153
156154/** 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+ }
158158
159159/** 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+ }
161163
162164/** 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+ }
164168
165169/** 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+ }
167173
168174/** A call to `html_safe` from within a controller. */
169- private class ActionControllerHtmlSafeCall extends HtmlSafeCall {
175+ private class ActionControllerHtmlSafeCall extends HtmlSafeCallImpl {
170176 ActionControllerHtmlSafeCall ( ) {
177+ this .getMethodName ( ) = "html_safe" and
171178 this .getEnclosingModule ( ) instanceof ActionControllerControllerClass
172179 }
173180}
174181
175182/** A call to `html_escape` from within a controller. */
176- private class ActionControllerHtmlEscapeCall extends HtmlEscapeCall {
183+ private class ActionControllerHtmlEscapeCall extends HtmlEscapeCallImpl {
177184 ActionControllerHtmlEscapeCall ( ) {
185+ // "h" is aliased to "html_escape" in ActiveSupport
186+ this .getMethodName ( ) = [ "html_escape" , "html_escape_once" , "h" , "sanitize" ] and
178187 this .getEnclosingModule ( ) instanceof ActionControllerControllerClass
179188 }
180189}
@@ -291,7 +300,7 @@ ActionControllerControllerClass getAssociatedControllerClass(ErbFile f) {
291300 // template file, `fp`. In this case, `f` inherits the associated
292301 // controller classes from `fp`.
293302 f .isPartial ( ) and
294- exists ( RenderCall r , ErbFile fp |
303+ exists ( Rails :: RenderCall r , ErbFile fp |
295304 r .getLocation ( ) .getFile ( ) = fp and
296305 r .getTemplateFile ( ) = f and
297306 result = getAssociatedControllerClass ( fp )
0 commit comments