Skip to content

Commit f302222

Browse files
authored
Merge pull request #7061 from github/hmac/actiondispatch
Ruby: Rails route resolution
2 parents 6483a92 + f276904 commit f302222

File tree

14 files changed

+1182
-15
lines changed

14 files changed

+1182
-15
lines changed

ruby/ql/lib/codeql/ruby/Frameworks.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ private import codeql.ruby.frameworks.StandardLibrary
1313
private import codeql.ruby.frameworks.Files
1414
private import codeql.ruby.frameworks.HttpClients
1515
private import codeql.ruby.frameworks.XmlParsing
16+
private import codeql.ruby.frameworks.ActionDispatch

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ private import codeql.ruby.dataflow.RemoteFlowSources
66
private import codeql.ruby.ast.internal.Module
77
private import codeql.ruby.ApiGraphs
88
private 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

Comments
 (0)