Skip to content

Commit 4644a88

Browse files
author
Alvaro Muñoz
committed
address code review comments
1 parent 642a138 commit 4644a88

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,30 @@ module Twirp {
1919
class ServiceInstantiation extends DataFlow::CallNode {
2020
ServiceInstantiation() {
2121
this =
22-
API::getTopLevelMember("Twirp").getMember("Service").getASubclass*().getAnInstantiation()
22+
API::getTopLevelMember("Twirp").getMember("Service").getASubclass().getAnInstantiation()
2323
}
2424

2525
/**
2626
* Gets a local source node for the Service instantiation argument (the service handler).
2727
*/
28-
DataFlow::LocalSourceNode getHandlerSource() { result = this.getArgument(0).getALocalSource() }
28+
private DataFlow::LocalSourceNode getHandlerSource() {
29+
result = this.getArgument(0).getALocalSource()
30+
}
2931

3032
/**
3133
* Gets the API::Node for the service handler's class.
3234
*/
33-
API::Node getHandlerClassApiNode() { result.getAnInstantiation() = this.getHandlerSource() }
34-
35-
/**
36-
* Gets the local source node for the service handler's class.
37-
*/
38-
DataFlow::LocalSourceNode getHandlerClassDataFlowNode() {
39-
result = this.getHandlerClassApiNode().asSource()
35+
private API::Node getAHandlerClassApiNode() {
36+
result.getAnInstantiation() = this.getHandlerSource()
4037
}
4138

4239
/**
4340
* Gets the AST module for the service handler's class.
4441
*/
45-
Ast::Module getHandlerClassAstNode() {
42+
private Ast::Module getAHandlerClassAstNode() {
4643
result =
47-
this.getHandlerClassDataFlowNode()
44+
this.getAHandlerClassApiNode()
45+
.asSource()
4846
.asExpr()
4947
.(CfgNodes::ExprNodes::ConstantReadAccessCfgNode)
5048
.getExpr()
@@ -54,16 +52,17 @@ module Twirp {
5452
/**
5553
* Gets a handler's method.
5654
*/
57-
Ast::Method getHandlerMethod() { result = this.getHandlerClassAstNode().getAnInstanceMethod() }
55+
Ast::Method getAHandlerMethod() {
56+
result = this.getAHandlerClassAstNode().getAnInstanceMethod()
57+
}
5858
}
5959

6060
/**
6161
* A Twirp client
6262
*/
6363
class ClientInstantiation extends DataFlow::CallNode {
6464
ClientInstantiation() {
65-
this =
66-
API::getTopLevelMember("Twirp").getMember("Client").getASubclass*().getAnInstantiation()
65+
this = API::getTopLevelMember("Twirp").getMember("Client").getASubclass().getAnInstantiation()
6766
}
6867
}
6968

@@ -76,7 +75,7 @@ module Twirp {
7675
class UnmarshaledParameter extends Http::Server::RequestInputAccess::Range,
7776
DataFlow::ParameterNode {
7877
UnmarshaledParameter() {
79-
exists(ServiceInstantiation i | i.getHandlerMethod().getParameter(0) = this.asParameter())
78+
exists(ServiceInstantiation i | i.getAHandlerMethod().getParameter(0) = this.asParameter())
8079
}
8180

8281
override string getSourceType() { result = "Twirp Unmarhaled Parameter" }
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
private import codeql.ruby.frameworks.Twirp
22
private import codeql.ruby.DataFlow
33

4-
query predicate sourceTest(DataFlow::Node s) { s instanceof Twirp::UnmarshaledParameter }
4+
query predicate sourceTest(Twirp::UnmarshaledParameter source) { any() }
55

6-
query predicate ssrfSinkTest(DataFlow::Node n) { n instanceof Twirp::ServiceUrlAsSsrfSink }
6+
query predicate ssrfSinkTest(Twirp::ServiceUrlAsSsrfSink sink) { any() }
77

8-
query predicate serviceInstantiationTest(DataFlow::Node n) {
9-
n instanceof Twirp::ServiceInstantiation
10-
}
8+
query predicate serviceInstantiationTest(Twirp::ServiceInstantiation si) { any() }

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

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)