Skip to content

Commit 0ca9852

Browse files
authored
Merge pull request #7325 from github/hmac/action-controller-private-methods
Ruby: Don't count private methods as Rails actions
2 parents b80a84c + e1d290d commit 0ca9852

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ class ActionControllerControllerClass extends ClassDeclaration {
5454
}
5555

5656
/**
57-
* An instance method defined within an `ActionController` controller class.
57+
* A public instance method defined within an `ActionController` controller class.
5858
* This may be the target of a route handler, if such a route is defined.
5959
*/
6060
class ActionControllerActionMethod extends Method, HTTP::Server::RequestHandler::Range {
6161
private ActionControllerControllerClass controllerClass;
6262

63-
ActionControllerActionMethod() { this = controllerClass.getAMethod() }
63+
ActionControllerActionMethod() { this = controllerClass.getAMethod() and not this.isPrivate() }
6464

6565
/**
6666
* Establishes a mapping between a method within the file

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ actionControllerControllerClasses
22
| ActiveRecordInjection.rb:27:1:58:3 | FooController |
33
| ActiveRecordInjection.rb:60:1:90:3 | BarController |
44
| ActiveRecordInjection.rb:92:1:96:3 | BazController |
5-
| app/controllers/foo/bars_controller.rb:3:1:25:3 | BarsController |
5+
| app/controllers/foo/bars_controller.rb:3:1:31:3 | BarsController |
66
actionControllerActionMethods
77
| ActiveRecordInjection.rb:32:3:57:5 | some_request_handler |
88
| ActiveRecordInjection.rb:61:3:69:5 | some_other_request_handler |
@@ -57,8 +57,8 @@ redirectToCalls
5757
| app/controllers/foo/bars_controller.rb:17:5:17:30 | call to redirect_to |
5858
actionControllerHelperMethods
5959
getAssociatedControllerClasses
60-
| app/controllers/foo/bars_controller.rb:3:1:25:3 | BarsController | app/views/foo/bars/_widget.html.erb:0:0:0:0 | app/views/foo/bars/_widget.html.erb |
61-
| app/controllers/foo/bars_controller.rb:3:1:25:3 | BarsController | app/views/foo/bars/show.html.erb:0:0:0:0 | app/views/foo/bars/show.html.erb |
60+
| app/controllers/foo/bars_controller.rb:3:1:31:3 | BarsController | app/views/foo/bars/_widget.html.erb:0:0:0:0 | app/views/foo/bars/_widget.html.erb |
61+
| app/controllers/foo/bars_controller.rb:3:1:31:3 | BarsController | app/views/foo/bars/show.html.erb:0:0:0:0 | app/views/foo/bars/show.html.erb |
6262
controllerTemplateFiles
63-
| app/controllers/foo/bars_controller.rb:3:1:25:3 | BarsController | app/views/foo/bars/_widget.html.erb:0:0:0:0 | app/views/foo/bars/_widget.html.erb |
64-
| app/controllers/foo/bars_controller.rb:3:1:25:3 | BarsController | app/views/foo/bars/show.html.erb:0:0:0:0 | app/views/foo/bars/show.html.erb |
63+
| app/controllers/foo/bars_controller.rb:3:1:31:3 | BarsController | app/views/foo/bars/_widget.html.erb:0:0:0:0 | app/views/foo/bars/_widget.html.erb |
64+
| app/controllers/foo/bars_controller.rb:3:1:31:3 | BarsController | app/views/foo/bars/show.html.erb:0:0:0:0 | app/views/foo/bars/show.html.erb |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rawCalls
1414
renderCalls
1515
| app/controllers/foo/bars_controller.rb:6:5:6:37 | call to render |
1616
| app/controllers/foo/bars_controller.rb:23:5:23:76 | call to render |
17+
| app/controllers/foo/bars_controller.rb:29:5:29:17 | call to render |
1718
| app/views/foo/bars/show.html.erb:31:5:31:89 | call to render |
1819
renderToCalls
1920
| app/controllers/foo/bars_controller.rb:15:16:15:97 | call to render_to_string |

ruby/ql/test/library-tests/frameworks/app/controllers/foo/bars_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,10 @@ def show
2222
dt = params[:text]
2323
render "foo/bars/show", locals: { display_text: dt, safe_text: "hello" }
2424
end
25+
26+
private
27+
28+
def unreachable_action
29+
render "show"
30+
end
2531
end

0 commit comments

Comments
 (0)