shrine 3.10.1 → 3.11.0
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 +12 -0
- data/doc/external/extensions.md +1 -0
- data/doc/getting_started.md +2 -2
- data/doc/plugins/remote_url.md +1 -1
- data/doc/release_notes/3.10.2.md +31 -0
- data/doc/release_notes/3.11.0.md +29 -0
- data/lib/shrine/plugins/_persistence.rb +3 -0
- data/lib/shrine/plugins/atomic_helpers.rb +2 -2
- data/lib/shrine/plugins/data_uri.rb +5 -1
- data/lib/shrine/plugins/derivation_endpoint.rb +13 -15
- data/lib/shrine/plugins/validation.rb +1 -0
- data/lib/shrine/storage/file_system.rb +1 -1
- data/lib/shrine/storage/linter.rb +1 -1
- data/lib/shrine/storage/s3.rb +14 -1
- data/lib/shrine/version.rb +2 -2
- data/shrine.gemspec +3 -3
- metadata +20 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ee3f16b8ddadc8935c215db855f7158f933b3e434d3161784a441e59f5c7cf61
|
|
4
|
+
data.tar.gz: 591e2466e243f0806581d080aeab45860852c3af6ca2f8b682f4d34928fb2c38
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 12ac806a5d6ad67fb89df03d804ba87e8ac24b64ad2e8132266f4f682083631e0aa13dca16f1e25758e7f72b7811e160c9846f468fa492fe672f1be57cfc5858
|
|
7
|
+
data.tar.gz: e3bd9124c10d56a5b294f8873ae7df2873adc51261e5312076dd78e4050a67ae24d6bd9927089a90050de136415230d213228889995534c29fc9dc02fdeb804b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 3.11.0 (2026-11-21)
|
|
2
|
+
|
|
3
|
+
* Require Ruby 3.3+ (@janko)
|
|
4
|
+
|
|
5
|
+
* `file_system` – Prevent path traversal outside of the storage directory in `FileSystem#delete_prefixed` (@MaNi4)
|
|
6
|
+
|
|
7
|
+
* `s3` – Build public `S3#url` with `:host` from the object key without generating the S3 URL first, which is 3-7x faster (@doutatsu)
|
|
8
|
+
|
|
9
|
+
## 3.10.2 (2026-10-11)
|
|
10
|
+
|
|
11
|
+
* `derivation_endpoint` – Prevent bypassing CDN caching by modifying the encoding or structure of the signed URL query string (@Antsiscool, @janko)
|
|
12
|
+
|
|
1
13
|
## 3.10.1 (2026-10-10)
|
|
2
14
|
|
|
3
15
|
* `model` – Make `Attacher#write` a no-op when the attacher isn't backed by a model, fixing `remove_invalid` raising `NoMethodError` on attachers without a record (@janko)
|
data/doc/external/extensions.md
CHANGED
|
@@ -7,6 +7,7 @@ title: Extensions
|
|
|
7
7
|
| Gem | Description |
|
|
8
8
|
| :---- | :---------- |
|
|
9
9
|
| [shrine-aliyun-oss](https://github.com/zillou/shrine-aliyun-oss) | Storage using [Alibaba Cloud OSS](https://www.alibabacloud.com/product/oss) |
|
|
10
|
+
| [shrine-bunny](https://github.com/doutatsu/shrine-bunny) | Storage using [Bunny Storage](https://bunny.net/storage/) |
|
|
10
11
|
| [shrine-cloudinary](https://github.com/shrinerb/shrine-cloudinary) | Storage using [Cloudinary](https://cloudinary.com/) |
|
|
11
12
|
| [shrine-flickr](https://github.com/shrinerb/shrine-flickr) | Storage using [Flickr](https://flickr.com/) |
|
|
12
13
|
| [shrine-fog](https://github.com/shrinerb/shrine-fog) | Storage using [Fog](http://fog.io/) |
|
data/doc/getting_started.md
CHANGED
|
@@ -314,8 +314,8 @@ Shrine is able to upload any IO-like object that implement methods [`#read`],
|
|
|
314
314
|
This includes but is not limited to the following objects:
|
|
315
315
|
|
|
316
316
|
* [`File`](https://ruby-doc.org/core/File.html)
|
|
317
|
-
* [`Tempfile`](https://ruby-
|
|
318
|
-
* [`StringIO`](https://ruby-
|
|
317
|
+
* [`Tempfile`](https://docs.ruby-lang.org/en/master/Tempfile.html)
|
|
318
|
+
* [`StringIO`](https://docs.ruby-lang.org/en/master/StringIO.html)
|
|
319
319
|
* [`ActionDispatch::Http::UploadedFile`](https://api.rubyonrails.org/classes/ActionDispatch/Http/UploadedFile.html)
|
|
320
320
|
* [`Shrine::RackFile`](https://shrinerb.com/docs/plugins/rack_file)
|
|
321
321
|
* [`Shrine::DataFile`](https://shrinerb.com/docs/plugins/data_uri)
|
data/doc/plugins/remote_url.md
CHANGED
|
@@ -195,6 +195,6 @@ plugin :remote_url, log_subscriber: nil
|
|
|
195
195
|
[remote_url]: https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/remote_url.rb
|
|
196
196
|
[Down]: https://github.com/janko/down
|
|
197
197
|
[Down::NetHttp]: https://github.com/janko/down#downnethttp
|
|
198
|
-
[open-uri]: https://ruby-
|
|
198
|
+
[open-uri]: https://docs.ruby-lang.org/en/master/OpenURI.html
|
|
199
199
|
[http.rb]: https://github.com/httprb/http
|
|
200
200
|
[shrine-url]: https://github.com/shrinerb/shrine-url
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Shrine 3.10.2
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Security
|
|
6
|
+
|
|
7
|
+
* The `derivation_endpoint` plugin now verifies the URL signature against the
|
|
8
|
+
URL exactly as it was received. Previously, query parameters were decoded and
|
|
9
|
+
re-encoded before verification, so the same signed URL could be requested
|
|
10
|
+
through an unlimited number of variants that all passed verification. Since
|
|
11
|
+
each variant is a separate cache key on a CDN, this could be used to bypass
|
|
12
|
+
CDN caching and repeatedly trigger derivations on the server:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
/derivations/thumbnail/...?type=image%2Fwebp&signature=abc123 # original
|
|
16
|
+
/derivations/thumbnail/...?%74ype=image%2Fwebp&signature=abc123 # encoded parameter name
|
|
17
|
+
/derivations/thumbnail/...?&&type=image%2Fwebp&signature=abc123 # empty parameters
|
|
18
|
+
/derivations/thumbnail/...?type=image%2Fwebp&signature=abc123?foo # appended query
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
These variants now return a `403 Forbidden` response. The `signature` query
|
|
22
|
+
parameter is also required to be the last parameter, which is where Shrine
|
|
23
|
+
always puts it.
|
|
24
|
+
|
|
25
|
+
## Backwards compatibility
|
|
26
|
+
|
|
27
|
+
* URLs generated by the `derivation_endpoint` plugin are unchanged, so
|
|
28
|
+
existing URLs remain valid. However, if a proxy between the client and your
|
|
29
|
+
application rewrites the query string (e.g. re-encodes characters, reorders
|
|
30
|
+
parameters, or appends tracking parameters), signature verification will now
|
|
31
|
+
fail for those requests.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Shrine 3.11.0
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Security
|
|
6
|
+
|
|
7
|
+
* `FileSystem#delete_prefixed` now raises a `Shrine::Error` when the given
|
|
8
|
+
prefix resolves outside of the storage directory, the same way other
|
|
9
|
+
`FileSystem` methods do. Previously, a prefix such as `"../"` would cause
|
|
10
|
+
files outside of the storage directory to be deleted.
|
|
11
|
+
|
|
12
|
+
## Performance improvements
|
|
13
|
+
|
|
14
|
+
* `S3#url` now builds public URLs with the `:host` option directly from the
|
|
15
|
+
object key, without first generating the S3 URL via
|
|
16
|
+
`Aws::S3::Object#public_url`. This makes generating such URLs 3-7x faster
|
|
17
|
+
and significantly reduces allocations.
|
|
18
|
+
|
|
19
|
+
```rb
|
|
20
|
+
s3.url("image.jpg", host: "https://cdn.example.com") # faster
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Backwards compatibility
|
|
24
|
+
|
|
25
|
+
* Shrine now requires Ruby 3.3 or later.
|
|
26
|
+
|
|
27
|
+
* When using `S3` with `force_path_style: true` and an endpoint whose host
|
|
28
|
+
contains the bucket name, public URLs generated with `:host` no longer
|
|
29
|
+
include the bucket name in the path, consistent with other path-style URLs.
|
|
@@ -22,6 +22,9 @@ class Shrine
|
|
|
22
22
|
plugin_name = plugin.to_s.split("::").last.downcase
|
|
23
23
|
|
|
24
24
|
plugin::AttacherMethods.module_eval do
|
|
25
|
+
# persistence methods are already defined if plugin was loaded before
|
|
26
|
+
next if method_defined?(:atomic_promote, false)
|
|
27
|
+
|
|
25
28
|
define_method :atomic_promote do |**options, &block|
|
|
26
29
|
return super(**options, &block) unless send(:"#{plugin_name}?")
|
|
27
30
|
|
|
@@ -43,13 +43,13 @@ class Shrine
|
|
|
43
43
|
#
|
|
44
44
|
# This more convenient to use with concrete persistence plugins, which
|
|
45
45
|
# provide defaults for reloading and persistence.
|
|
46
|
-
def abstract_atomic_promote(reload:, persist:, **, &
|
|
46
|
+
def abstract_atomic_promote(reload:, persist:, **, &)
|
|
47
47
|
original_file = file
|
|
48
48
|
|
|
49
49
|
result = promote(**)
|
|
50
50
|
|
|
51
51
|
begin
|
|
52
|
-
abstract_atomic_persist(original_file, reload:, persist:, &
|
|
52
|
+
abstract_atomic_persist(original_file, reload:, persist:, &)
|
|
53
53
|
result
|
|
54
54
|
rescue Shrine::AttachmentChanged
|
|
55
55
|
destroy_attached
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
require "base64"
|
|
4
4
|
require "strscan"
|
|
5
|
-
|
|
5
|
+
if RUBY_VERSION >= "4.0"
|
|
6
|
+
require "cgi/escape" # CGI.unescape
|
|
7
|
+
else
|
|
8
|
+
require "cgi/util" # cgi/escape on Ruby < 4.0 doesn't fully define CGI.unescape
|
|
9
|
+
end
|
|
6
10
|
require "stringio"
|
|
7
11
|
require "forwardable"
|
|
8
12
|
|
|
@@ -717,29 +717,27 @@ class Shrine
|
|
|
717
717
|
|
|
718
718
|
# Returns a URL with the `signature` query parameter
|
|
719
719
|
def sign_url(url)
|
|
720
|
-
path, query = url.split("?")
|
|
720
|
+
path, query = url.split("?", 2)
|
|
721
721
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
query = Rack::Utils.build_query(params)
|
|
722
|
+
signature = generate_signature("#{path}?#{query}")
|
|
723
|
+
query = [query, "signature=#{signature}"].reject { |part| part.to_s.empty? }.join("&")
|
|
726
724
|
|
|
727
725
|
"#{path}?#{query}"
|
|
728
726
|
end
|
|
729
727
|
|
|
730
|
-
#
|
|
731
|
-
# value in the `signature` query parameter. Raises
|
|
732
|
-
# the `signature` parameter is missing or its value
|
|
733
|
-
# calculated signature.
|
|
728
|
+
# Calculates the signature from the URL and checks whether it matches the
|
|
729
|
+
# value in the trailing `signature` query parameter. Raises
|
|
730
|
+
# `InvalidSignature` if the `signature` parameter is missing or its value
|
|
731
|
+
# doesn't match the calculated signature. The URL is verified as is,
|
|
732
|
+
# without any normalization, so that each signed URL has only one valid
|
|
733
|
+
# form (otherwise variants of it could be used to bypass CDN caching).
|
|
734
734
|
def verify_url(url)
|
|
735
|
-
path, query = url.split("?")
|
|
736
|
-
|
|
737
|
-
params = Rack::Utils.parse_query(query.to_s)
|
|
738
|
-
signature = params.delete("signature")
|
|
735
|
+
path, query = url.split("?", 2)
|
|
739
736
|
|
|
740
|
-
|
|
737
|
+
params = query.to_s.split("&", -1)
|
|
738
|
+
signature = params.pop.delete_prefix("signature=") if params.last&.start_with?("signature=")
|
|
741
739
|
|
|
742
|
-
verify_signature("#{path}?#{
|
|
740
|
+
verify_signature("#{path}?#{params.join("&")}", signature)
|
|
743
741
|
end
|
|
744
742
|
|
|
745
743
|
def verify_signature(string, signature)
|
|
@@ -93,7 +93,7 @@ class Shrine
|
|
|
93
93
|
#
|
|
94
94
|
# file_system.delete_prefixed("somekey/derivatives/")
|
|
95
95
|
def delete_prefixed(delete_prefix)
|
|
96
|
-
FileUtils.rm_rf
|
|
96
|
+
FileUtils.rm_rf path(delete_prefix)
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
# Deletes all files from the #directory. If a block is passed in, deletes
|
data/lib/shrine/storage/s3.rb
CHANGED
|
@@ -10,6 +10,11 @@ require "content_disposition"
|
|
|
10
10
|
|
|
11
11
|
require "uri"
|
|
12
12
|
require "tempfile"
|
|
13
|
+
if RUBY_VERSION >= "4.0"
|
|
14
|
+
require "cgi/escape" # CGI.escape
|
|
15
|
+
else
|
|
16
|
+
require "cgi/util" # CGI.escape
|
|
17
|
+
end
|
|
13
18
|
|
|
14
19
|
class Shrine
|
|
15
20
|
module Storage
|
|
@@ -146,6 +151,9 @@ class Shrine
|
|
|
146
151
|
# [`Aws::S3::Object#presigned_url`]: http://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Object.html#presigned_url-instance_method
|
|
147
152
|
# [`Aws::S3::Object#public_url`]: http://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Object.html#public_url-instance_method
|
|
148
153
|
def url(id, public: self.public, host: nil, **)
|
|
154
|
+
# With :host, only the escaped object key of the public S3 URL is kept, so the S3 URL is not built.
|
|
155
|
+
return URI.join(host, escape_path(object_key(id))).to_s if host && public && !signer
|
|
156
|
+
|
|
149
157
|
if public || signer
|
|
150
158
|
url = object(id).public_url(**)
|
|
151
159
|
else
|
|
@@ -356,6 +364,11 @@ class Shrine
|
|
|
356
364
|
[*prefix, id].join("/")
|
|
357
365
|
end
|
|
358
366
|
|
|
367
|
+
# Escapes the object key the same way as Aws::S3::Object#public_url.
|
|
368
|
+
def escape_path(key)
|
|
369
|
+
key.gsub(/[^\/]+/) { |segment| CGI.escape(segment.encode("UTF-8")).gsub("+", "%20").gsub("%7E", "~") }
|
|
370
|
+
end
|
|
371
|
+
|
|
359
372
|
# Adds support for Aws::S3::Encryption::Client.
|
|
360
373
|
module ClientSideEncryption
|
|
361
374
|
attr_reader :encryption_client
|
|
@@ -385,7 +398,7 @@ class Shrine
|
|
|
385
398
|
# Encryption client v2 warns against streaming download, so we first
|
|
386
399
|
# download all content into a file.
|
|
387
400
|
tempfile = Tempfile.new("shrine-s3", binmode: true)
|
|
388
|
-
|
|
401
|
+
encryption_client.get_object(response_target: tempfile, bucket: bucket.name, key: object_key(id), **)
|
|
389
402
|
tempfile.rewind
|
|
390
403
|
|
|
391
404
|
chunks = Enumerator.new do |yielder|
|
data/lib/shrine/version.rb
CHANGED
data/shrine.gemspec
CHANGED
|
@@ -4,7 +4,7 @@ Gem::Specification.new do |gem|
|
|
|
4
4
|
gem.name = "shrine"
|
|
5
5
|
gem.version = Shrine.version
|
|
6
6
|
|
|
7
|
-
gem.required_ruby_version = ">= 3.
|
|
7
|
+
gem.required_ruby_version = ">= 3.3"
|
|
8
8
|
|
|
9
9
|
gem.summary = "Toolkit for file attachments in Ruby applications"
|
|
10
10
|
gem.description = <<-END
|
|
@@ -41,7 +41,8 @@ direct uploads for fully asynchronous user experience.
|
|
|
41
41
|
# general testing helpers
|
|
42
42
|
gem.add_development_dependency "rake", ">= 11.1"
|
|
43
43
|
gem.add_development_dependency "minitest", "~> 6.0"
|
|
44
|
-
gem.add_development_dependency "mocha", "~>
|
|
44
|
+
gem.add_development_dependency "mocha", "~> 3.0"
|
|
45
|
+
gem.add_development_dependency "warning", "~> 1.5"
|
|
45
46
|
|
|
46
47
|
# for endpoint plugins
|
|
47
48
|
gem.add_development_dependency "rack", ">= 2", "< 4"
|
|
@@ -51,7 +52,6 @@ direct uploads for fully asynchronous user experience.
|
|
|
51
52
|
# for determine_mime_type plugin
|
|
52
53
|
gem.add_development_dependency "mimemagic", ">= 0.3.2"
|
|
53
54
|
gem.add_development_dependency "marcel"
|
|
54
|
-
gem.add_development_dependency "ruby-filemagic", "~> 0.7" unless RUBY_ENGINE == "jruby" || ENV["CI"]
|
|
55
55
|
|
|
56
56
|
# for determine_mime_type and infer_extension plugins
|
|
57
57
|
gem.add_development_dependency "mime-types"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shrine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Janko Marohnić
|
|
@@ -85,14 +85,28 @@ dependencies:
|
|
|
85
85
|
requirements:
|
|
86
86
|
- - "~>"
|
|
87
87
|
- !ruby/object:Gem::Version
|
|
88
|
-
version: '
|
|
88
|
+
version: '3.0'
|
|
89
89
|
type: :development
|
|
90
90
|
prerelease: false
|
|
91
91
|
version_requirements: !ruby/object:Gem::Requirement
|
|
92
92
|
requirements:
|
|
93
93
|
- - "~>"
|
|
94
94
|
- !ruby/object:Gem::Version
|
|
95
|
-
version: '
|
|
95
|
+
version: '3.0'
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: warning
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - "~>"
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '1.5'
|
|
103
|
+
type: :development
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - "~>"
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '1.5'
|
|
96
110
|
- !ruby/object:Gem::Dependency
|
|
97
111
|
name: rack
|
|
98
112
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -169,20 +183,6 @@ dependencies:
|
|
|
169
183
|
- - ">="
|
|
170
184
|
- !ruby/object:Gem::Version
|
|
171
185
|
version: '0'
|
|
172
|
-
- !ruby/object:Gem::Dependency
|
|
173
|
-
name: ruby-filemagic
|
|
174
|
-
requirement: !ruby/object:Gem::Requirement
|
|
175
|
-
requirements:
|
|
176
|
-
- - "~>"
|
|
177
|
-
- !ruby/object:Gem::Version
|
|
178
|
-
version: '0.7'
|
|
179
|
-
type: :development
|
|
180
|
-
prerelease: false
|
|
181
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
182
|
-
requirements:
|
|
183
|
-
- - "~>"
|
|
184
|
-
- !ruby/object:Gem::Version
|
|
185
|
-
version: '0.7'
|
|
186
186
|
- !ruby/object:Gem::Dependency
|
|
187
187
|
name: mime-types
|
|
188
188
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -491,6 +491,8 @@ files:
|
|
|
491
491
|
- doc/release_notes/3.1.0.md
|
|
492
492
|
- doc/release_notes/3.10.0.md
|
|
493
493
|
- doc/release_notes/3.10.1.md
|
|
494
|
+
- doc/release_notes/3.10.2.md
|
|
495
|
+
- doc/release_notes/3.11.0.md
|
|
494
496
|
- doc/release_notes/3.2.0.md
|
|
495
497
|
- doc/release_notes/3.2.1.md
|
|
496
498
|
- doc/release_notes/3.2.2.md
|
|
@@ -589,7 +591,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
589
591
|
requirements:
|
|
590
592
|
- - ">="
|
|
591
593
|
- !ruby/object:Gem::Version
|
|
592
|
-
version: '3.
|
|
594
|
+
version: '3.3'
|
|
593
595
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
594
596
|
requirements:
|
|
595
597
|
- - ">="
|