Skip to content

Commit aed5b80

Browse files
committed
Don't allow calling Kernel methods via loader/saver options
1 parent 12e7cf5 commit aed5b80

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
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+
* [minimagick] Don't allow calling Kernel options via `loader`/`saver` options (@janko)
4+
15
## 1.12.2 (2022-03-01)
26

37
* Prevent remote shell execution when using `#apply` with operations coming from user input (@janko)

lib/image_processing/mini_magick.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ def disallow_split_layers!(destination_path)
213213
def apply_options(magick, define: {}, **options)
214214
options.each do |option, value|
215215
case value
216-
when true, nil then magick.send(option)
217-
when false then magick.send(option).+
218-
else magick.send(option, *value)
216+
when true, nil then magick.public_send(option)
217+
when false then magick.public_send(option).+
218+
else magick.public_send(option, *value)
219219
end
220220
end
221221

test/mini_magick_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,26 @@
173173
assert_dimensions [600, 800], result
174174
end
175175

176+
it "doesn't allow calling Kernel methods via loader/saver options" do
177+
error = assert_raises(MiniMagick::Error) do
178+
ImageProcessing::MiniMagick
179+
.source(@portrait)
180+
.loader(system: "touch test/malicious.txt")
181+
.call
182+
end
183+
184+
assert_match "unrecognized option `-system'", error.message
185+
186+
error = assert_raises(MiniMagick::Error) do
187+
ImageProcessing::MiniMagick
188+
.source(@portrait)
189+
.saver(system: "touch test/malicious.txt")
190+
.call
191+
end
192+
193+
assert_match "unrecognized option `-system'", error.message
194+
end
195+
176196
describe ".valid_image?" do
177197
it "returns true for correct images" do
178198
assert ImageProcessing::MiniMagick.valid_image?(@portrait)

0 commit comments

Comments
 (0)