@@ -6,6 +6,7 @@ private import codeql.ruby.dataflow.RemoteFlowSources
6
6
private import codeql.ruby.ast.internal.Module
7
7
private import codeql.ruby.ApiGraphs
8
8
private import ActionView
9
+ private import codeql.ruby.frameworks.ActionDispatch
9
10
10
11
/**
11
12
* A `ClassDeclaration` for a class that extends `ActionController::Base`.
@@ -69,6 +70,26 @@ class ActionControllerActionMethod extends Method, HTTP::Server::RequestHandler:
69
70
// not end at an explicit render or redirect
70
71
/** Gets the controller class containing this method. */
71
72
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 ( )
72
93
}
73
94
74
95
// A method call with a `self` receiver from within a controller class
0 commit comments