Skip to content

Commit db20e7d

Browse files
committed
Ruby: add ActionCable channel RPC params as remote-flow sources
1 parent 07f50e2 commit db20e7d

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
private import codeql.ruby.AST
77
private import codeql.ruby.Concepts
88
private import codeql.ruby.ApiGraphs
9+
private import codeql.ruby.DataFlow
10+
private import codeql.ruby.dataflow.RemoteFlowSources
911
private import codeql.ruby.frameworks.stdlib.Logger::Logger as StdlibLogger
1012

1113
/**
@@ -26,4 +28,33 @@ module ActionCable {
2628
}
2729
}
2830
}
31+
32+
/**
33+
* The data argument in an RPC endpoint method on a subclass of
34+
* `ActionCable::Channel::Base`, considered as a remote flow source.
35+
*/
36+
class ActionCableChannelRpcParam extends RemoteFlowSource::Range {
37+
ActionCableChannelRpcParam() {
38+
exists(DataFlow::MethodNode m |
39+
// Any method on a subclass of `ActionCable::Channel::Base`
40+
// automatically becomes an RPC endpoint
41+
m =
42+
DataFlow::getConstant("ActionCable")
43+
.getConstant("Channel")
44+
.getConstant("Base")
45+
.getADescendentModule()
46+
.getAnOwnInstanceMethod() and
47+
// as long as it's public
48+
m.asCallableAstNode().isPublic() and
49+
// and is not called `subscribed` or `unsubscribed`.
50+
not m.getMethodName() = ["subscribed", "unsubscribed"]
51+
|
52+
// If the method takes a parameter, it contains data from the remote
53+
// request.
54+
this = m.getParameter(0)
55+
)
56+
}
57+
58+
override string getSourceType() { result = "ActionCable channel RPC data" }
59+
}
2960
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
loggerInstantiations
12
| action_cable.rb:1:1:1:54 | call to new |
3+
remoteFlowSources
4+
| action_cable.rb:9:10:9:13 | data |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import codeql.ruby.frameworks.ActionCable
22
import codeql.ruby.frameworks.stdlib.Logger
3+
import codeql.ruby.dataflow.RemoteFlowSources
34

45
query predicate loggerInstantiations(Logger::LoggerInstantiation l) { any() }
6+
7+
query predicate remoteFlowSources(RemoteFlowSource s) { any() }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
ActionCable::Connection::TaggedLoggerProxy.new(logger)
2+
3+
class MyChannel < ActionCable::Channel::Base
4+
# An RPC endpoint without the optional data parm, so no remote flow source.
5+
def foo
6+
end
7+
8+
# An RPC endpoint including the optional data parm, which is a remote flow source.
9+
def bar(data)
10+
end
11+
end

0 commit comments

Comments
 (0)