Skip to content

Commit a03c068

Browse files
committed
Ruby: Add some more command injection sinks
1 parent c22cbf5 commit a03c068

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

ruby/ql/lib/codeql/ruby/frameworks/core/Kernel.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,19 @@ module Kernel {
130130
* `Kernel.spawn` takes the same argument forms as `Kernel.system`.
131131
* See `KernelSystemCall` for details.
132132
* Ruby documentation: https://docs.ruby-lang.org/en/3.0.0/Kernel.html#method-i-spawn
133+
* Methods with the same effect exist in the `Process` and `PTY` classes, so they are also modeled here.
133134
* TODO: document and handle the env and option arguments.
134135
* ```
135136
* spawn([env,] command... [,options]) -> pid
136137
* ```
137138
*/
138-
class KernelSpawnCall extends SystemCommandExecution::Range instanceof KernelMethodCall {
139-
KernelSpawnCall() { this.getMethodName() = "spawn" }
139+
class KernelSpawnCall extends SystemCommandExecution::Range instanceof DataFlow::CallNode {
140+
KernelSpawnCall() {
141+
this.getMethodName() = "spawn" and
142+
this instanceof KernelMethodCall
143+
or
144+
this = DataFlow::getConstant(["Process", "PTY"]).getAMethodCall("spawn")
145+
}
140146

141147
override DataFlow::Node getAnArgument() { result = super.getArgument(_) }
142148

ruby/ql/lib/codeql/ruby/frameworks/stdlib/Open3.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ private import codeql.ruby.ApiGraphs
77
private import codeql.ruby.Concepts
88

99
/**
10-
* Provides modeling for the `Open3` library.
10+
* Provides modeling for the `Open3` and `Open4` libraries.
1111
*/
1212
module Open3 {
1313
/**
@@ -18,8 +18,10 @@ module Open3 {
1818
class Open3Call extends SystemCommandExecution::Range instanceof DataFlow::CallNode {
1919
Open3Call() {
2020
this =
21-
API::getTopLevelMember("Open3")
22-
.getAMethodCall(["popen3", "popen2", "popen2e", "capture3", "capture2", "capture2e"])
21+
API::getTopLevelMember(["Open3", "Open4"])
22+
.getAMethodCall([
23+
"popen3", "popen2", "popen2e", "capture3", "capture2", "capture2e", "popen4"
24+
])
2325
}
2426

2527
override DataFlow::Node getAnArgument() { result = super.getArgument(_) }

0 commit comments

Comments
 (0)