@@ -6,6 +6,7 @@ private import codeql.ruby.dataflow.RemoteFlowSources
66private import codeql.ruby.ast.internal.Module
77private import codeql.ruby.ApiGraphs
88private import ActionView
9+ private import codeql.ruby.frameworks.ActionDispatch
910
1011/**
1112 * A `ClassDeclaration` for a class that extends `ActionController::Base`.
@@ -69,6 +70,26 @@ class ActionControllerActionMethod extends Method, HTTP::Server::RequestHandler:
6970 // not end at an explicit render or redirect
7071 /** Gets the controller class containing this method. */
7172 ActionControllerControllerClass getControllerClass ( ) { result = controllerClass }
73+
74+ /**
75+ * Gets a route to this handler, if one exists.
76+ * May return multiple results.
77+ */
78+ ActionDispatch:: Route getARoute ( ) {
79+ exists ( string name |
80+ isRoute ( result , name , controllerClass ) and
81+ isActionControllerMethod ( this , name , controllerClass )
82+ )
83+ }
84+ }
85+
86+ pragma [ nomagic]
87+ private predicate isRoute (
88+ ActionDispatch:: Route route , string name , ActionControllerControllerClass controllerClass
89+ ) {
90+ route .getController ( ) + "_controller" =
91+ ActionDispatch:: underscore ( namespaceDeclaration ( controllerClass ) ) and
92+ name = route .getAction ( )
7293}
7394
7495// A method call with a `self` receiver from within a controller class
0 commit comments