Skip to content

Commit 5b6dd78

Browse files
committed
Add changes for NonConstantKernelOpenQuery
1 parent 88282ad commit 5b6dd78

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

ruby/ql/src/queries/security/cwe-078/NonConstantKernelOpen.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
2-
* @name Use of `Kernel.open` or `IO.read` with a non-constant value
3-
* @description Using `Kernel.open` or `IO.read` may allow a malicious
2+
* @name Use of `Kernel.open` or `IO.read` or similar sinks with a non-constant value
3+
* @description Using `Kernel.open`, `IO.read`, `IO.write`, `IO.binread`, `IO.binwrite`,
4+
* `IO.foreach`, `IO.readlines`, or `URI.open` may allow a malicious
45
* user to execute arbitrary system commands.
56
* @kind problem
67
* @problem.severity warning
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
| NonConstantKernelOpen.rb:4:5:4:14 | call to open | Call to Kernel.open with a non-constant value. Consider replacing it with File.open. |
22
| NonConstantKernelOpen.rb:5:5:5:17 | call to read | Call to IO.read with a non-constant value. Consider replacing it with File.read. |
3-
| NonConstantKernelOpen.rb:9:5:9:21 | call to open | Call to Kernel.open with a non-constant value. Consider replacing it with File.open. |
4-
| NonConstantKernelOpen.rb:19:5:19:33 | call to open | Call to Kernel.open with a non-constant value. Consider replacing it with File.open. |
3+
| NonConstantKernelOpen.rb:6:5:6:18 | call to write | Call to IO.write with a non-constant value. Consider replacing it with File.write. |
4+
| NonConstantKernelOpen.rb:7:5:7:20 | call to binread | Call to IO.binread with a non-constant value. Consider replacing it with File.binread. |
5+
| NonConstantKernelOpen.rb:8:5:8:21 | call to binwrite | Call to IO.binwrite with a non-constant value. Consider replacing it with File.binwrite. |
6+
| NonConstantKernelOpen.rb:9:5:9:20 | call to foreach | Call to IO.foreach with a non-constant value. Consider replacing it with File.foreach. |
7+
| NonConstantKernelOpen.rb:10:5:10:22 | call to readlines | Call to IO.readlines with a non-constant value. Consider replacing it with File.readlines. |
8+
| NonConstantKernelOpen.rb:11:5:11:18 | call to open | Call to URI.open with a non-constant value. Consider replacing it with URI(<uri>).open. |
9+
| NonConstantKernelOpen.rb:15:5:15:21 | call to open | Call to Kernel.open with a non-constant value. Consider replacing it with File.open. |
10+
| NonConstantKernelOpen.rb:25:5:25:33 | call to open | Call to Kernel.open with a non-constant value. Consider replacing it with File.open. |

ruby/ql/test/query-tests/security/cwe-078/NonConstantKernelOpen/NonConstantKernelOpen.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ def create
33
file = params[:file]
44
open(file) # BAD
55
IO.read(file) # BAD
6+
IO.write(file) # BAD
7+
IO.binread(file) # BAD
8+
IO.binwrite(file) # BAD
9+
IO.foreach(file) # BAD
10+
IO.readlines(file) # BAD
11+
URI.open(file) # BAD
612

713
File.open(file).read # GOOD
814

0 commit comments

Comments
 (0)