image_processing 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/image_processing/chainable.rb +16 -6
- data/lib/image_processing/mini_magick.rb +5 -4
- data/lib/image_processing/processor.rb +11 -3
- data/lib/image_processing/version.rb +1 -1
- data/lib/image_processing.rb +17 -16
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3f36b1a00b35a05403a2c6dd77f94912dbbca311cb6939556cbb7e9eb66cd702
|
|
4
|
+
data.tar.gz: bce160c3fcff5a046447c334c4c5440386080d355b0899c30b5b1ea6e89922c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61b02322af114f81116e9f3600d5f331cacb8b6c299a78a15c9891d56beb92ee56f4181b3349b64087bd3d801aa90029ee31e5e897847ea4bb9739589bcc3305
|
|
7
|
+
data.tar.gz: ba62cf185ca3ac4a19582936c3fbca176b7e8312185fd3505438b247e839a877ac53781cf518311b6a5ff3601111529393a00649b0e395b5b42bbeec3de27f8d
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## 2.2.1 (2026-11-21)
|
|
2
|
+
|
|
3
|
+
* Prevent remote code execution when operation names or MiniMagick loader/saver option names come from user input and a library such as ActiveSupport adds methods like `Object#try` to every object (reported by @hgrgr)
|
|
4
|
+
|
|
5
|
+
* [minimagick] Allow loader/saver options named like private Kernel methods again, such as `format:` and `print:`
|
|
6
|
+
|
|
1
7
|
## 2.2.0 (2026-09-29)
|
|
2
8
|
|
|
3
9
|
* Save in the `#convert` format when the destination path has no extension, such as a `/dev/fd/N` path (thanks to @flavorjones)
|
|
@@ -85,17 +85,27 @@ module ImageProcessing
|
|
|
85
85
|
|
|
86
86
|
private
|
|
87
87
|
|
|
88
|
-
#
|
|
89
|
-
#
|
|
90
|
-
#
|
|
91
|
-
#
|
|
88
|
+
# Operation names may come from user input, so only allow Chainable's own
|
|
89
|
+
# builder methods and unknown names (which become processor operations via
|
|
90
|
+
# #method_missing). This prevents dispatching to methods such as
|
|
91
|
+
# `Kernel#send`, `BasicObject#instance_eval` or ActiveSupport's
|
|
92
|
+
# `Object#try`, which would allow remote code execution. The processor
|
|
93
|
+
# enforces the same guard when operations are dispatched, which also covers
|
|
94
|
+
# paths that bypass this early check (e.g. the #operation meta-builder).
|
|
92
95
|
#
|
|
93
96
|
# Bang names are rejected here because they are Chainable's execution
|
|
94
|
-
# shortcut (see #method_missing), not operations to chain.
|
|
97
|
+
# shortcut (see #method_missing), not operations to chain. #branch and
|
|
98
|
+
# #call are rejected because they would let input overwrite internal
|
|
99
|
+
# builder options or the destination path.
|
|
95
100
|
def invalid_operation?(name)
|
|
96
|
-
name.end_with?("!") ||
|
|
101
|
+
name.end_with?("!") ||
|
|
102
|
+
NON_OPERATION_METHODS.include?(name.to_s) ||
|
|
103
|
+
!ImageProcessing.allowed_method?(self, name, [Chainable])
|
|
97
104
|
end
|
|
98
105
|
|
|
106
|
+
# Chainable methods that must not be reachable through #apply.
|
|
107
|
+
NON_OPERATION_METHODS = %w[branch call].freeze
|
|
108
|
+
|
|
99
109
|
# Assume that any unknown method names an operation supported by the
|
|
100
110
|
# processor. Add a bang ("!") if you want processing to be performed.
|
|
101
111
|
def method_missing(name, ...)
|
|
@@ -248,10 +248,11 @@ module ImageProcessing
|
|
|
248
248
|
# Applies options from the provided hash.
|
|
249
249
|
def apply_options(magick, define: {}, **options)
|
|
250
250
|
options.each do |option, value|
|
|
251
|
-
# Loader/saver option names may come from user input, so
|
|
252
|
-
#
|
|
253
|
-
# #
|
|
254
|
-
|
|
251
|
+
# Loader/saver option names may come from user input, so only
|
|
252
|
+
# dispatch to MiniMagick::Tool's own methods or CLI options handled
|
|
253
|
+
# by #method_missing, never to methods such as #instance_eval,
|
|
254
|
+
# #send or ActiveSupport's #try.
|
|
255
|
+
unless ImageProcessing.allowed_method?(magick, option, [::MiniMagick::Tool])
|
|
255
256
|
raise Error, "#{option.inspect} is not a valid option"
|
|
256
257
|
end
|
|
257
258
|
|
|
@@ -60,12 +60,20 @@ module ImageProcessing
|
|
|
60
60
|
# around via the #operation meta-builder, #method_missing, or a nested
|
|
61
61
|
# #send. This is the single point every operation is finally dispatched
|
|
62
62
|
# through, so enforcing the guard here closes all of those paths.
|
|
63
|
-
|
|
63
|
+
#
|
|
64
|
+
# Macros defined by the processor are called on the processor; anything
|
|
65
|
+
# else is forwarded to the accumulator, but only if the accumulator's
|
|
66
|
+
# class defines it or handles it via #method_missing. Methods inherited
|
|
67
|
+
# from elsewhere (Ruby core, or modules mixed into every object such as
|
|
68
|
+
# ActiveSupport's Object#try) are rejected.
|
|
69
|
+
if respond_to?(name) && method(name).owner <= ImageProcessing::Processor
|
|
70
|
+
receiver = self
|
|
71
|
+
elsif ImageProcessing.allowed_method?(@accumulator, name, [self.class::ACCUMULATOR_CLASS])
|
|
72
|
+
receiver = @accumulator
|
|
73
|
+
else
|
|
64
74
|
fail Error, "#{name.inspect} is not a valid operation"
|
|
65
75
|
end
|
|
66
76
|
|
|
67
|
-
receiver = respond_to?(name) ? self : @accumulator
|
|
68
|
-
|
|
69
77
|
if args.last.is_a?(Hash)
|
|
70
78
|
kwargs = args.pop
|
|
71
79
|
receiver.public_send(name, *args, **kwargs, &block)
|
data/lib/image_processing.rb
CHANGED
|
@@ -7,23 +7,24 @@ require "image_processing/version"
|
|
|
7
7
|
module ImageProcessing
|
|
8
8
|
Error = Class.new(StandardError)
|
|
9
9
|
|
|
10
|
-
#
|
|
11
|
-
# from user input
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
# Whether +name+ can be safely dispatched on +receiver+ when the name comes
|
|
11
|
+
# from user input. A name is allowed if the receiver doesn't define it, in
|
|
12
|
+
# which case it falls through to #method_missing and becomes an image
|
|
13
|
+
# operation, or if it's defined by one of +allowed_owners+ (or a subclass).
|
|
14
|
+
#
|
|
15
|
+
# Any other method is rejected: Ruby core methods such as Kernel#send or
|
|
16
|
+
# BasicObject#instance_eval, but also methods that other libraries mix into
|
|
17
|
+
# every object, such as ActiveSupport's Object#try. Allowing only known
|
|
18
|
+
# owners keeps the guard correct regardless of what else is loaded.
|
|
19
|
+
#
|
|
20
|
+
# Private methods are ignored, because public_send can't call them and
|
|
21
|
+
# forwards them to #method_missing instead. This keeps CLI options named
|
|
22
|
+
# like private Kernel methods (e.g. -format, -print) working.
|
|
23
|
+
def self.allowed_method?(receiver, name, allowed_owners)
|
|
24
|
+
owner = receiver.public_method(name.to_s).owner
|
|
25
|
+
allowed_owners.any? { |allowed_owner| owner <= allowed_owner }
|
|
23
26
|
rescue NameError
|
|
24
|
-
|
|
25
|
-
# the receiver (which will reject it if it is not a real operation).
|
|
26
|
-
false
|
|
27
|
+
true
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
autoload :MiniMagick, "image_processing/mini_magick"
|