Skip to content

Commit 038e457

Browse files
committed
Prevent remote shell execution in #apply
If the operations are coming from user input, this could allow the user to execute arbitrary shell commands via `Kernel#system` and `Kernel#spawn`: ImageProcessing::Vips.apply({ system: "echo something" }) We prevent this by using `#public_send` instead of `#send`, which goes to method missing instead of calling private methods, which include `Kernel#system` and `Kernel#spawn`.
1 parent 183c058 commit 038e457

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## HEAD
2+
3+
* Prevent remote shell execution when using `#apply` with operations coming from user input (@janko)
4+
15
## 1.12.1 (2020-11-06)
26

37
* Fix format fallback for files ending with a dot on Ruby 2.7+ (@coding-chimp)

lib/image_processing/chainable.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ def instrumenter(&block)
3434
def apply(operations)
3535
operations.inject(self) do |builder, (name, argument)|
3636
if argument == true || argument == nil
37-
builder.send(name)
37+
builder.public_send(name)
3838
elsif argument.is_a?(Array)
39-
builder.send(name, *argument)
39+
builder.public_send(name, *argument)
4040
elsif argument.is_a?(Hash)
41-
builder.send(name, **argument)
41+
builder.public_send(name, **argument)
4242
else
43-
builder.send(name, argument)
43+
builder.public_send(name, argument)
4444
end
4545
end
4646
end

test/pipeline_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,19 @@
258258
ImageProcessing::Vips.valid?(@portrait)
259259
end
260260
end
261+
262+
it "doesn't allow making system calls" do
263+
ImageProcessing::Vips.source(@portrait).apply(system: "touch foo.txt")
264+
refute File.exist?("foo.txt")
265+
266+
assert_raises Vips::Error do
267+
ImageProcessing::Vips.source(@portrait).spawn("touch foo.txt").call
268+
end
269+
refute File.exist?("foo.txt")
270+
271+
assert_raises MiniMagick::Error do
272+
ImageProcessing::MiniMagick.source(@portrait).spawn("touch foo.txt").call
273+
end
274+
refute File.exist?("foo.txt")
275+
end
261276
end

0 commit comments

Comments
 (0)