Skip to content

Commit

Permalink
Don't allow calling Kernel methods via loader/saver options
Browse files Browse the repository at this point in the history
  • Loading branch information
janko committed Jul 31, 2022
1 parent 12e7cf5 commit aed5b80
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## HEAD

* [minimagick] Don't allow calling Kernel options via `loader`/`saver` options (@janko)

## 1.12.2 (2022-03-01)

* Prevent remote shell execution when using `#apply` with operations coming from user input (@janko)
Expand Down
6 changes: 3 additions & 3 deletions lib/image_processing/mini_magick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ def disallow_split_layers!(destination_path)
def apply_options(magick, define: {}, **options)
options.each do |option, value|
case value
when true, nil then magick.send(option)
when false then magick.send(option).+
else magick.send(option, *value)
when true, nil then magick.public_send(option)
when false then magick.public_send(option).+
else magick.public_send(option, *value)
end
end

Expand Down
20 changes: 20 additions & 0 deletions test/mini_magick_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,26 @@
assert_dimensions [600, 800], result
end

it "doesn't allow calling Kernel methods via loader/saver options" do
error = assert_raises(MiniMagick::Error) do
ImageProcessing::MiniMagick
.source(@portrait)
.loader(system: "touch test/malicious.txt")
.call
end

assert_match "unrecognized option `-system'", error.message

error = assert_raises(MiniMagick::Error) do
ImageProcessing::MiniMagick
.source(@portrait)
.saver(system: "touch test/malicious.txt")
.call
end

assert_match "unrecognized option `-system'", error.message
end

describe ".valid_image?" do
it "returns true for correct images" do
assert ImageProcessing::MiniMagick.valid_image?(@portrait)
Expand Down

0 comments on commit aed5b80

Please sign in to comment.