Skip to content

Commit 28a2320

Browse files
committed
Ruby: Identify ActionController::Metal controllers
Subclasses of `ActionController::Metal` are stripped-down controllers. We want to recognise them as ActionController controllers. There are some common ActionController methods that are not available in Metal, but these are not likely to be used anyway as they would throw an exception, so I don't think there's much harm in including them in the modelling.
1 parent 56e3334 commit 28a2320

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ class ActionControllerControllerClass extends ClassDeclaration {
3232
API::getTopLevelMember("ActionController").getMember("Base"),
3333
// In Rails applications `ApplicationController` typically extends `ActionController::Base`, but we
3434
// treat it separately in case the `ApplicationController` definition is not in the database.
35-
API::getTopLevelMember("ApplicationController")
35+
API::getTopLevelMember("ApplicationController"),
36+
// ActionController::Metal technically doesn't contain all of the
37+
// methods available in Base, such as those for rendering views.
38+
// However we prefer to be over-sensitive in this case in order to find
39+
// more results.
40+
API::getTopLevelMember("ActionController").getMember("Metal")
3641
].getASubclass().getAValueReachableFromSource().asExpr().getExpr()
3742
}
3843

ruby/ql/test/library-tests/frameworks/ActionController.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ actionControllerControllerClasses
77
| app/controllers/foo/bars_controller.rb:3:1:46:3 | BarsController |
88
| app/controllers/photos_controller.rb:1:1:4:3 | PhotosController |
99
| app/controllers/posts_controller.rb:1:1:10:3 | PostsController |
10+
| app/controllers/tags_controller.rb:1:1:2:3 | TagsController |
1011
| app/controllers/users/notifications_controller.rb:2:3:5:5 | NotificationsController |
1112
actionControllerActionMethods
1213
| active_record/ActiveRecord.rb:27:3:38:5 | some_request_handler |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class TagsController < ActionController::Metal
2+
end

0 commit comments

Comments
 (0)