activestorage 8.1.3.1 → 8.1.4.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 +190 -0
- data/app/controllers/active_storage/blobs/proxy_controller.rb +18 -4
- data/app/controllers/active_storage/blobs/redirect_controller.rb +20 -4
- data/app/controllers/active_storage/representations/proxy_controller.rb +18 -4
- data/app/controllers/active_storage/representations/redirect_controller.rb +21 -4
- data/app/controllers/concerns/active_storage/streaming.rb +9 -4
- data/app/models/active_storage/attachment.rb +7 -3
- data/app/models/active_storage/blob.rb +33 -13
- data/app/models/active_storage/filename.rb +5 -4
- data/app/models/active_storage/variant.rb +1 -1
- data/lib/active_storage/analyzer/audio_analyzer.rb +3 -0
- data/lib/active_storage/analyzer/image_analyzer/image_magick.rb +3 -8
- data/lib/active_storage/analyzer/video_analyzer.rb +3 -0
- data/lib/active_storage/attached/changes/create_many.rb +2 -1
- data/lib/active_storage/attached/changes/create_one.rb +2 -1
- data/lib/active_storage/attached/changes/delete_many.rb +2 -1
- data/lib/active_storage/attached/changes/delete_one.rb +2 -1
- data/lib/active_storage/attached/many.rb +4 -0
- data/lib/active_storage/attached/model.rb +13 -2
- data/lib/active_storage/attached/one.rb +6 -0
- data/lib/active_storage/engine.rb +16 -0
- data/lib/active_storage/gem_version.rb +1 -1
- data/lib/active_storage/image_magick/policy.xml +68 -0
- data/lib/active_storage/image_magick.rb +63 -0
- data/lib/active_storage/previewer/video_previewer.rb +1 -1
- data/lib/active_storage/previewer.rb +1 -1
- data/lib/active_storage/service/gcs_service.rb +11 -18
- data/lib/active_storage/service/mirror_service.rb +5 -3
- data/lib/active_storage/transformers/image_magick.rb +2 -0
- data/lib/active_storage.rb +10 -0
- metadata +15 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fdfb78984fbd5e8de07c60266b6996cf48474e219120bf89a916ea96aeb7a190
|
|
4
|
+
data.tar.gz: 752b81997b178d7cd7473b1c27d5199bb6e03bebc301b4660eee0f380cfa95c2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9cd250255e0da480e917eafac48c4f36751e9c7e3c54c3b3cc63d1ab82cb5d12a30738b7489d1dbce08b4158a506605423612d6f29d2cee75f17afa291b0c01e
|
|
7
|
+
data.tar.gz: 4b185e00d70788a9a2f22f5e49681927177fcb9eb22918593a7b22d48a7f2de6448eb6732af5e699e75dd541c341888f2e357c9e167b99f44aeca2c38ce5a9fe
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,193 @@
|
|
|
1
|
+
## Rails 8.1.4.1 (November 03, 2026) ##
|
|
2
|
+
|
|
3
|
+
* Preserve committed proxy responses when a storage error interrupts a
|
|
4
|
+
streamed download.
|
|
5
|
+
|
|
6
|
+
[GHSA-4v2w-w6g6-f8f8]
|
|
7
|
+
|
|
8
|
+
*Jeremy Daer*
|
|
9
|
+
|
|
10
|
+
* Derive `ActiveStorage::Filename#base` and `#extension` from the sanitized
|
|
11
|
+
filename.
|
|
12
|
+
|
|
13
|
+
This prevents null bytes and invalid byte sequences in stored filename
|
|
14
|
+
metadata from raising when a blob is opened or represented. Existing blob
|
|
15
|
+
records are handled without a data migration.
|
|
16
|
+
|
|
17
|
+
[GHSA-p2pm-g2h6-7j5j]
|
|
18
|
+
|
|
19
|
+
*Jeremy Daer*
|
|
20
|
+
|
|
21
|
+
* Ship an ImageMagick security policy and apply it to every ImageMagick
|
|
22
|
+
process MiniMagick spawns.
|
|
23
|
+
|
|
24
|
+
ImageMagick chooses a coder from the content of the file it is given, and
|
|
25
|
+
some coders act on files named inside the image rather than on the image
|
|
26
|
+
itself. Active Storage constrained none of them, so an uploaded file could
|
|
27
|
+
reach any coder the host's policy allowed, through the ImageMagick analyzer
|
|
28
|
+
at attach time, with no variant or `analyze` call in the application.
|
|
29
|
+
|
|
30
|
+
Active Storage now ships a `policy.xml` in
|
|
31
|
+
`ActiveStorage::ImageMagick::POLICY_DIRECTORY` and prepends that directory
|
|
32
|
+
to `MAGICK_CONFIGURE_PATH` through `MiniMagick.cli_env`. ImageMagick applies
|
|
33
|
+
every policy file on its search path, so the shipped policy adds to the
|
|
34
|
+
host's policy rather than replacing it. A `MAGICK_CONFIGURE_PATH` set in the
|
|
35
|
+
environment or in `MiniMagick.cli_env`, including by an initializer or
|
|
36
|
+
dotenv, is kept after the shipped directory.
|
|
37
|
+
|
|
38
|
+
The shipped policy denies the coders that script ImageMagick (`MSL`), read
|
|
39
|
+
or delete files other than the image (`TEXT`, `EPHEMERAL`), fetch remote
|
|
40
|
+
references (`URL`, `HTTP`, `HTTPS`, `FTP`), display to a screen (`SHOW`,
|
|
41
|
+
`WIN`, `PLT`), or hand the file to Ghostscript (the `PS`, `EPS`, `EPT` and
|
|
42
|
+
`PDF` coders, every alias of them, and the `gs` delegate), or reach a file
|
|
43
|
+
directly (`FILE`, `MPC`, `XPS`, `PCL`), and it refuses `@filename`
|
|
44
|
+
indirection. The policy applies to every ImageMagick command MiniMagick
|
|
45
|
+
runs, not only Active Storage's.
|
|
46
|
+
|
|
47
|
+
These applications must act:
|
|
48
|
+
|
|
49
|
+
* One whose variant processor is `:mini_magick` has to use mini_magick 5.1
|
|
50
|
+
or later, which applying the policy requires. With an older mini_magick,
|
|
51
|
+
it raises at boot.
|
|
52
|
+
* One that renders PostScript or PDF through ImageMagick has to re-allow
|
|
53
|
+
the `gs` delegate and the coders it uses in the host's `policy.xml`. A
|
|
54
|
+
host policy that allows a coder overrides the shipped deny.
|
|
55
|
+
* One that replaces `MiniMagick.cli_env` after it boots, clears the
|
|
56
|
+
environment with `MiniMagick.cli_prefix`, or installs its own
|
|
57
|
+
`MiniMagick::Shell` never receives the shipped policy and has to carry
|
|
58
|
+
its rules in ImageMagick's system policy. So does one that uses
|
|
59
|
+
GraphicsMagick, which does not read ImageMagick policies.
|
|
60
|
+
|
|
61
|
+
Every other application needs no change. See "ImageMagick Security Policy"
|
|
62
|
+
in the Active Storage guide.
|
|
63
|
+
|
|
64
|
+
[GHSA-f3w6-w445-fwh9]
|
|
65
|
+
|
|
66
|
+
*Mike Dalessio*
|
|
67
|
+
|
|
68
|
+
* Enforce the declared content length on Google Cloud Storage direct uploads.
|
|
69
|
+
|
|
70
|
+
The signed URL now requires an `x-goog-content-length-range` header matching the blob's
|
|
71
|
+
`byte_size`, so Cloud Storage rejects a body of any other size.
|
|
72
|
+
|
|
73
|
+
Browsers send the new header, so a bucket's CORS configuration must list
|
|
74
|
+
`x-goog-content-length-range` in `responseHeader`, or direct uploads from the browser fail.
|
|
75
|
+
|
|
76
|
+
[GHSA-hfr4-8rjc-97m2]
|
|
77
|
+
|
|
78
|
+
*Mike Dalessio*
|
|
79
|
+
|
|
80
|
+
* Sign GCS direct uploads with V2 when `cache_control` is set.
|
|
81
|
+
|
|
82
|
+
V4 signatures did not bind the Content-Type or Content-MD5 headers, so the uploader could
|
|
83
|
+
choose the stored Content-Type. Direct-upload URLs with `cache_control` are no longer limited
|
|
84
|
+
to 7 days, and the client sends `Cache-Control` unsigned.
|
|
85
|
+
|
|
86
|
+
[GHSA-3w93-6hmw-whh4]
|
|
87
|
+
|
|
88
|
+
*Mike Dalessio*
|
|
89
|
+
|
|
90
|
+
* Stop an uploaded filename choosing the extension of the tempfile Active
|
|
91
|
+
Storage hands to an external tool.
|
|
92
|
+
|
|
93
|
+
`ActiveStorage::Blob#open` named its tempfile after the uploaded filename,
|
|
94
|
+
extension and all. Tools that select a decoder from the extension alone,
|
|
95
|
+
such as FFmpeg's AviSynth demuxer on `.avs`, therefore took their
|
|
96
|
+
instructions from the uploader. The extension is now kept only when it
|
|
97
|
+
denotes the blob's recorded media type, and dropped otherwise.
|
|
98
|
+
|
|
99
|
+
[GHSA-v924-7rp8-4mxh]
|
|
100
|
+
|
|
101
|
+
*Mike Dalessio*
|
|
102
|
+
|
|
103
|
+
* Restrict the formats ffmpeg and ffprobe will open when previewing and
|
|
104
|
+
analyzing video and audio.
|
|
105
|
+
|
|
106
|
+
Active Storage now passes `-format_whitelist` before the input at every
|
|
107
|
+
ffmpeg and ffprobe call site, limiting demuxer selection to common audio and
|
|
108
|
+
video container formats. Configure the list with
|
|
109
|
+
`config.active_storage.ffmpeg_allowed_formats`, or set it to `nil` to let
|
|
110
|
+
ffmpeg choose any demuxer it was built with.
|
|
111
|
+
|
|
112
|
+
Files in other formats, such as MXF, DV, AC3, WavPack, AU, W64, and raw
|
|
113
|
+
H.264 or MPEG-1/2 video streams, now fail to preview with
|
|
114
|
+
`ActiveStorage::PreviewError`, and their analysis stores no media metadata
|
|
115
|
+
and logs a warning. Add their demuxers to the list to keep them.
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
config.active_storage.ffmpeg_allowed_formats += %w[ mxf ]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
[GHSA-3f4q-8x5m-76v8]
|
|
122
|
+
|
|
123
|
+
*Mike Dalessio*
|
|
124
|
+
|
|
125
|
+
## Rails 8.1.4 (September 24, 2026) ##
|
|
126
|
+
|
|
127
|
+
* Warn instead of aborting boot when `image_processing` 2.x is installed without `ruby-vips`
|
|
128
|
+
or `mini_magick`.
|
|
129
|
+
|
|
130
|
+
Both gems became soft dependencies in `image_processing` 2.0, and the `LoadError` raised for
|
|
131
|
+
a missing one names that gem instead of `image_processing`. Active Storage did not recognize
|
|
132
|
+
the message, so it re-raised rather than logging its usual warning.
|
|
133
|
+
|
|
134
|
+
Fixes #58413.
|
|
135
|
+
|
|
136
|
+
*Janko Marohnić*
|
|
137
|
+
|
|
138
|
+
* Fix `MirrorService#mirror` losing blob metadata when copying to mirrors.
|
|
139
|
+
|
|
140
|
+
Mirrored copies on S3, Azure, and GCS were served as `application/octet-stream`
|
|
141
|
+
because `content_type`, `filename`, `disposition`, and `custom_metadata` were
|
|
142
|
+
dropped. Forward the blob's `service_metadata` to each mirror's upload.
|
|
143
|
+
|
|
144
|
+
Fixes #57270.
|
|
145
|
+
|
|
146
|
+
*Maksim Romanov* + *Andrii Furmanets*
|
|
147
|
+
|
|
148
|
+
* Prevent `ActiveStorage.touch_attachment_records = false` from crashing the attachment of a Blob.
|
|
149
|
+
|
|
150
|
+
When `ActiveStorage.touch_attachment_records` was set to `false`, attaching a existing Blob to a Record
|
|
151
|
+
would raise an error. This is now fixed.
|
|
152
|
+
|
|
153
|
+
*Edouard Chin*
|
|
154
|
+
|
|
155
|
+
* Fix `MirrorService#mirror` raising `ActiveStorage::IntegrityError` when
|
|
156
|
+
mirroring without a checksum (e.g., `track_variants: false`).
|
|
157
|
+
|
|
158
|
+
*Denis Savchuk*
|
|
159
|
+
|
|
160
|
+
* Preserve attachment changes when converting record to another class using STI.
|
|
161
|
+
|
|
162
|
+
*fatkodima*
|
|
163
|
+
|
|
164
|
+
* Correct unexpected behavior resulting from dependent: :purge when using
|
|
165
|
+
has_one_attached or has_many_attached. Fixes #36423.
|
|
166
|
+
|
|
167
|
+
*Mark Oveson*
|
|
168
|
+
|
|
169
|
+
* Define `as_json` on `ActiveStorage::Attached::One` and `ActiveStorage::Attached::Many`.
|
|
170
|
+
|
|
171
|
+
The proxies hold a back-reference to the owning record in `@record`. Without an explicit
|
|
172
|
+
`as_json`, the default `Object#as_json` fall back serialized `instance_values`, which made
|
|
173
|
+
`record.to_json` recurse infinitely whenever the attached name collided with a model
|
|
174
|
+
attribute (e.g. an `ignored_columns` column brought back by `select('*')`).
|
|
175
|
+
|
|
176
|
+
`Attached::One#as_json` now returns the attachment record's JSON when attached and `nil`
|
|
177
|
+
otherwise. `Attached::Many#as_json` returns the attachment records' JSON as an array.
|
|
178
|
+
|
|
179
|
+
*Renxiang Cai*
|
|
180
|
+
|
|
181
|
+
* Fix Rails hanging when generating video previews
|
|
182
|
+
|
|
183
|
+
When Rails runs in a background process group, ffmpeg's attempt to configure the terminal for
|
|
184
|
+
interactive input would send SIGTTOU to the Rails process, suspending it indefinitely.
|
|
185
|
+
|
|
186
|
+
Fixed by explicitly passing /dev/null to ffmpeg's stdin.
|
|
187
|
+
|
|
188
|
+
*Jonathan del Strother*
|
|
189
|
+
|
|
190
|
+
|
|
1
191
|
## Rails 8.1.3.1 (July 29, 2026) ##
|
|
2
192
|
|
|
3
193
|
* Disable libvips's unfuzzed image loaders and savers.
|
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# Finds a blob by a +signed_id+ and proxies the file through the application.
|
|
4
|
+
# The blob is streamed from storage directly to the response. This avoids having
|
|
5
|
+
# a redirect and makes files easier to cache.
|
|
4
6
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
7
|
+
# The +signed_id+s make URLs hard to guess but permanent by design, allowing the URLs to be cached.
|
|
8
|
+
# The response sets the HTTP cache to public and allows browsers and proxies to cache it indefinitely.
|
|
9
|
+
#
|
|
10
|
+
# The URLs created for this controller are set to never expire by default.
|
|
11
|
+
# To make URLs expire, pass the +expires_in+ option when generating the URL:
|
|
12
|
+
#
|
|
13
|
+
# rails_storage_proxy_url(blob, expires_in: 1.minute)
|
|
14
|
+
#
|
|
15
|
+
# Or set the default for all Active Storage URLs:
|
|
16
|
+
#
|
|
17
|
+
# config.active_storage.urls_expire_in = 1.day
|
|
18
|
+
#
|
|
19
|
+
# WARNING: All Active Storage controllers are publicly accessible by default.
|
|
20
|
+
# Anyone who knows the URL can access the file, even if the rest of your application requires
|
|
21
|
+
# authentication. If your files require access control consider implementing
|
|
8
22
|
# {Authenticated Controllers}[https://guides.rubyonrails.org/active_storage_overview.html#authenticated-controllers].
|
|
9
23
|
class ActiveStorage::Blobs::ProxyController < ActiveStorage::BaseController
|
|
10
24
|
include ActiveStorage::SetBlob
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# Finds a blob by a +signed_id+ and redirects to a blob's expiring service URL.
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
5
|
+
# The +signed_id+s make URLs hard to guess but permanent by design, allowing the URLs to be cached.
|
|
6
|
+
#
|
|
7
|
+
# The URLs created for this controller are set to never expire by default.
|
|
8
|
+
# To make URLs expire, pass the +expires_in+ option when generating the URL:
|
|
9
|
+
#
|
|
10
|
+
# rails_storage_redirect_url(blob, expires_in: 1.minute)
|
|
11
|
+
#
|
|
12
|
+
# Or set the default for all Active Storage URLs:
|
|
13
|
+
#
|
|
14
|
+
# config.active_storage.urls_expire_in = 1.day
|
|
15
|
+
#
|
|
16
|
+
# The service URLs are set to expire in 5 minutes by default.
|
|
17
|
+
# The default can be changed for all service URLs:
|
|
18
|
+
#
|
|
19
|
+
# config.active_storage.service_urls_expire_in = 1.hour
|
|
20
|
+
#
|
|
21
|
+
# WARNING: All Active Storage controllers are publicly accessible by default.
|
|
22
|
+
# Anyone who knows the URL can access the file, even if the rest of your application requires
|
|
23
|
+
# authentication. If your files require access control consider implementing
|
|
8
24
|
# {Authenticated Controllers}[https://guides.rubyonrails.org/active_storage_overview.html#authenticated-controllers].
|
|
9
25
|
class ActiveStorage::Blobs::RedirectController < ActiveStorage::BaseController
|
|
10
26
|
include ActiveStorage::SetBlob
|
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# Finds a representation by a +signed_id+ and a +variation_key+, and proxies the file through the application.
|
|
4
|
+
# The representation is streamed from storage directly to the response. This avoids having
|
|
5
|
+
# a redirect and makes files easier to cache.
|
|
4
6
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
7
|
+
# The +signed_id+s make URLs hard to guess but permanent by design, allowing the URLs to be cached.
|
|
8
|
+
# The response sets the HTTP cache to public and allows browsers and proxies to cache it indefinitely.
|
|
9
|
+
#
|
|
10
|
+
# The URLs created for this controller are set to never expire by default.
|
|
11
|
+
# To make URLs expire, pass the +expires_in+ option when generating the URL:
|
|
12
|
+
#
|
|
13
|
+
# rails_storage_proxy_url(representation, expires_in: 1.minute)
|
|
14
|
+
#
|
|
15
|
+
# Or set the default for all Active Storage URLs:
|
|
16
|
+
#
|
|
17
|
+
# config.active_storage.urls_expire_in = 1.day
|
|
18
|
+
#
|
|
19
|
+
# WARNING: All Active Storage controllers are publicly accessible by default.
|
|
20
|
+
# Anyone who knows the URL can access the file, even if the rest of your application requires
|
|
21
|
+
# authentication. If your files require access control consider implementing
|
|
8
22
|
# {Authenticated Controllers}[https://guides.rubyonrails.org/active_storage_overview.html#authenticated-controllers].
|
|
9
23
|
class ActiveStorage::Representations::ProxyController < ActiveStorage::Representations::BaseController
|
|
10
24
|
include ActiveStorage::Streaming
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# Finds a representation by a +signed_id+ and a +variation_key+, and redirects to a representation's expiring
|
|
4
|
+
# service URL.
|
|
4
5
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
6
|
+
# The +signed_id+s make URLs hard to guess but permanent by design, allowing the URLs to be cached.
|
|
7
|
+
#
|
|
8
|
+
# The URLs created for this controller are set to never expire by default.
|
|
9
|
+
# To make URLs expire, pass the +expires_in+ option when generating the URL:
|
|
10
|
+
#
|
|
11
|
+
# rails_storage_redirect_url(representation, expires_in: 1.minute)
|
|
12
|
+
#
|
|
13
|
+
# Or set the default for all Active Storage URLs:
|
|
14
|
+
#
|
|
15
|
+
# config.active_storage.urls_expire_in = 1.day
|
|
16
|
+
#
|
|
17
|
+
# The service URLs are set to expire in 5 minutes by default.
|
|
18
|
+
# The default can be changed for all service URLs:
|
|
19
|
+
#
|
|
20
|
+
# config.active_storage.service_urls_expire_in = 1.hour
|
|
21
|
+
#
|
|
22
|
+
# WARNING: All Active Storage controllers are publicly accessible by default.
|
|
23
|
+
# Anyone who knows the URL can access the file, even if the rest of your application requires
|
|
24
|
+
# authentication. If your files require access control consider implementing
|
|
8
25
|
# {Authenticated Controllers}[https://guides.rubyonrails.org/active_storage_overview.html#authenticated-controllers].
|
|
9
26
|
class ActiveStorage::Representations::RedirectController < ActiveStorage::Representations::BaseController
|
|
10
27
|
def show
|
|
@@ -69,13 +69,18 @@ module ActiveStorage::Streaming
|
|
|
69
69
|
stream.write chunk
|
|
70
70
|
end
|
|
71
71
|
rescue ActiveStorage::FileNotFoundError
|
|
72
|
+
raise if response.committed?
|
|
73
|
+
|
|
72
74
|
expires_now
|
|
73
75
|
head :not_found
|
|
74
76
|
rescue
|
|
75
|
-
#
|
|
76
|
-
# Change the status to 500 manually.
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
# Until the first chunk is written, status and caching headers are set
|
|
78
|
+
# but not committed. Change the status to 500 manually.
|
|
79
|
+
unless response.committed?
|
|
80
|
+
expires_now
|
|
81
|
+
head :internal_server_error
|
|
82
|
+
end
|
|
83
|
+
|
|
79
84
|
raise
|
|
80
85
|
end
|
|
81
86
|
end
|
|
@@ -34,7 +34,7 @@ class ActiveStorage::Attachment < ActiveStorage::Record
|
|
|
34
34
|
delegate :signed_id, to: :blob
|
|
35
35
|
|
|
36
36
|
after_create_commit :mirror_blob_later, :analyze_blob_later, :transform_variants_later
|
|
37
|
-
after_destroy_commit :
|
|
37
|
+
after_destroy_commit :purge_dependent_blob
|
|
38
38
|
|
|
39
39
|
##
|
|
40
40
|
# :singleton-method:
|
|
@@ -147,8 +147,12 @@ class ActiveStorage::Attachment < ActiveStorage::Record
|
|
|
147
147
|
end
|
|
148
148
|
end
|
|
149
149
|
|
|
150
|
-
def
|
|
151
|
-
|
|
150
|
+
def purge_dependent_blob
|
|
151
|
+
if dependent == :purge_later
|
|
152
|
+
blob&.purge_later
|
|
153
|
+
elsif dependent == :purge
|
|
154
|
+
blob&.purge
|
|
155
|
+
end
|
|
152
156
|
end
|
|
153
157
|
|
|
154
158
|
def dependent
|
|
@@ -282,6 +282,16 @@ class ActiveStorage::Blob < ActiveStorage::Record
|
|
|
282
282
|
service.compose(keys, key, **service_metadata)
|
|
283
283
|
end
|
|
284
284
|
|
|
285
|
+
def service_metadata # :nodoc:
|
|
286
|
+
if forcibly_serve_as_binary?
|
|
287
|
+
{ content_type: ActiveStorage.binary_content_type, disposition: :attachment, filename: filename, custom_metadata: custom_metadata }
|
|
288
|
+
elsif !allowed_inline?
|
|
289
|
+
{ content_type: content_type, disposition: :attachment, filename: filename, custom_metadata: custom_metadata }
|
|
290
|
+
else
|
|
291
|
+
{ content_type: content_type, custom_metadata: custom_metadata }
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
285
295
|
# Downloads the file associated with this blob. If no block is given, the entire file is read into memory and returned.
|
|
286
296
|
# That'll use a lot of RAM for very large files. If a block is given, then the download is streamed and yielded in chunks.
|
|
287
297
|
def download(&block)
|
|
@@ -295,7 +305,8 @@ class ActiveStorage::Blob < ActiveStorage::Record
|
|
|
295
305
|
|
|
296
306
|
# Downloads the blob to a tempfile on disk. Yields the tempfile.
|
|
297
307
|
#
|
|
298
|
-
# The tempfile's name is prefixed with +ActiveStorage-+ and the blob's ID.
|
|
308
|
+
# The tempfile's name is prefixed with +ActiveStorage-+ and the blob's ID. It keeps the blob filename's
|
|
309
|
+
# extension when that extension denotes the blob's content type, and has no extension otherwise.
|
|
299
310
|
#
|
|
300
311
|
# By default, the tempfile is created in <tt>Dir.tmpdir</tt>. Pass +tmpdir:+ to create it in a different directory:
|
|
301
312
|
#
|
|
@@ -311,7 +322,7 @@ class ActiveStorage::Blob < ActiveStorage::Record
|
|
|
311
322
|
key,
|
|
312
323
|
checksum: checksum,
|
|
313
324
|
verify: !composed,
|
|
314
|
-
name: [ "ActiveStorage-#{id}-",
|
|
325
|
+
name: [ "ActiveStorage-#{id}-", tempfile_extension ],
|
|
315
326
|
tmpdir: tmpdir,
|
|
316
327
|
&block
|
|
317
328
|
)
|
|
@@ -350,6 +361,25 @@ class ActiveStorage::Blob < ActiveStorage::Record
|
|
|
350
361
|
end
|
|
351
362
|
|
|
352
363
|
private
|
|
364
|
+
# The extension is there for tools that cannot tell the type from the bytes (316d87e4: ImageMagick
|
|
365
|
+
# needs it for an SVG with no XML declaration), but some tools choose a decoder on it alone: FFmpeg
|
|
366
|
+
# runs a `.avs` file as an AviSynth script. So the uploaded extension is kept only when it denotes
|
|
367
|
+
# the blob's media type.
|
|
368
|
+
def tempfile_extension
|
|
369
|
+
extension = filename.extension_with_delimiter
|
|
370
|
+
return "" if extension.blank?
|
|
371
|
+
|
|
372
|
+
type_for_extension = Marcel::MimeType.for(name: filename.to_s)
|
|
373
|
+
return "" if type_for_extension == Marcel::MimeType::BINARY || type_for_extension != media_type
|
|
374
|
+
|
|
375
|
+
extension
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
# Marcel answers in canonical lowercase, so drop parameters and case before comparing.
|
|
379
|
+
def media_type
|
|
380
|
+
content_type.to_s.split(";").first.to_s.strip.downcase
|
|
381
|
+
end
|
|
382
|
+
|
|
353
383
|
def compute_checksum_in_chunks(io)
|
|
354
384
|
raise ArgumentError, "io must be rewindable" unless io.respond_to?(:rewind)
|
|
355
385
|
|
|
@@ -371,16 +401,6 @@ class ActiveStorage::Blob < ActiveStorage::Record
|
|
|
371
401
|
ActiveStorage.web_image_content_types.include?(content_type)
|
|
372
402
|
end
|
|
373
403
|
|
|
374
|
-
def service_metadata
|
|
375
|
-
if forcibly_serve_as_binary?
|
|
376
|
-
{ content_type: ActiveStorage.binary_content_type, disposition: :attachment, filename: filename, custom_metadata: custom_metadata }
|
|
377
|
-
elsif !allowed_inline?
|
|
378
|
-
{ content_type: content_type, disposition: :attachment, filename: filename, custom_metadata: custom_metadata }
|
|
379
|
-
else
|
|
380
|
-
{ content_type: content_type, custom_metadata: custom_metadata }
|
|
381
|
-
end
|
|
382
|
-
end
|
|
383
|
-
|
|
384
404
|
def touch_attachments
|
|
385
405
|
attachments.then do |relation|
|
|
386
406
|
if ActiveStorage.touch_attachment_records
|
|
@@ -389,7 +409,7 @@ class ActiveStorage::Blob < ActiveStorage::Record
|
|
|
389
409
|
relation
|
|
390
410
|
end
|
|
391
411
|
end.each do |attachment|
|
|
392
|
-
attachment.touch
|
|
412
|
+
attachment.touch unless attachment.new_record?
|
|
393
413
|
end
|
|
394
414
|
end
|
|
395
415
|
|
|
@@ -25,7 +25,7 @@ class ActiveStorage::Filename
|
|
|
25
25
|
# ActiveStorage::Filename.new("racecar").base # => "racecar"
|
|
26
26
|
# ActiveStorage::Filename.new(".gitignore").base # => ".gitignore"
|
|
27
27
|
def base
|
|
28
|
-
File.basename
|
|
28
|
+
File.basename sanitized, extension_with_delimiter
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
# Returns the extension of the filename (i.e. the substring following the last dot, excluding a dot at the
|
|
@@ -35,7 +35,7 @@ class ActiveStorage::Filename
|
|
|
35
35
|
# ActiveStorage::Filename.new("racecar").extension_with_delimiter # => ""
|
|
36
36
|
# ActiveStorage::Filename.new(".gitignore").extension_with_delimiter # => ""
|
|
37
37
|
def extension_with_delimiter
|
|
38
|
-
File.extname
|
|
38
|
+
File.extname sanitized
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# Returns the extension of the filename (i.e. the substring following the last dot, excluding a dot at
|
|
@@ -55,9 +55,10 @@ class ActiveStorage::Filename
|
|
|
55
55
|
# ActiveStorage::Filename.new("foo:bar.jpg").sanitized # => "foo-bar.jpg"
|
|
56
56
|
# ActiveStorage::Filename.new("foo/bar.jpg").sanitized # => "foo-bar.jpg"
|
|
57
57
|
#
|
|
58
|
-
# Characters considered unsafe for storage (e.g. \, $, and the RTL override character) are
|
|
58
|
+
# Characters considered unsafe for storage (e.g. \, $, the null character, and the RTL override character) are
|
|
59
|
+
# replaced with a dash.
|
|
59
60
|
def sanitized
|
|
60
|
-
@filename.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "�").strip.tr("\u{202E}%$|:;/<>?*\"\t\r\n\\", "-")
|
|
61
|
+
@filename.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "�").strip.tr("\u{202E}\u{0000}%$|:;/<>?*\"\t\r\n\\", "-")
|
|
61
62
|
end
|
|
62
63
|
|
|
63
64
|
# Returns the sanitized version of the filename.
|
|
@@ -78,7 +78,7 @@ class ActiveStorage::Variant
|
|
|
78
78
|
#
|
|
79
79
|
# Use <tt>url_for(variant)</tt> (or the implied form, like <tt>link_to variant</tt> or <tt>redirect_to variant</tt>) to get the stable URL
|
|
80
80
|
# for a variant that points to the ActiveStorage::Representations::ProxyController or ActiveStorage::Representations::RedirectController,
|
|
81
|
-
# which in turn will use this +
|
|
81
|
+
# which in turn will use this +url+ method for its redirection.
|
|
82
82
|
def url(expires_in: ActiveStorage.service_urls_expire_in, disposition: :inline)
|
|
83
83
|
service.url key, expires_in: expires_in, disposition: disposition, filename: filename, content_type: content_type
|
|
84
84
|
end
|
|
@@ -60,9 +60,12 @@ module ActiveStorage
|
|
|
60
60
|
"-show_streams",
|
|
61
61
|
"-show_format",
|
|
62
62
|
"-v", "error",
|
|
63
|
+
*ActiveStorage.ffmpeg_format_whitelist_arguments,
|
|
63
64
|
file.path
|
|
64
65
|
]) do |output|
|
|
65
66
|
JSON.parse(output.read)
|
|
67
|
+
end.tap do
|
|
68
|
+
logger.warn "Audio analysis failed because ffprobe exited with status #{$?.exitstatus}. The file may be corrupt, or in a format outside config.active_storage.ffmpeg_allowed_formats." unless $?.success?
|
|
66
69
|
end
|
|
67
70
|
end
|
|
68
71
|
rescue Errno::ENOENT
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
gem "mini_magick"
|
|
5
|
-
require "mini_magick"
|
|
6
|
-
ActiveStorage::MINIMAGICK_AVAILABLE = true # :nodoc:
|
|
7
|
-
rescue LoadError => error
|
|
8
|
-
ActiveStorage::MINIMAGICK_AVAILABLE = false # :nodoc:
|
|
9
|
-
raise error unless error.message.include?("mini_magick")
|
|
10
|
-
end
|
|
3
|
+
require "active_storage/image_magick"
|
|
11
4
|
|
|
12
5
|
module ActiveStorage
|
|
13
6
|
# This analyzer relies on the third-party {MiniMagick}[https://github.com/minimagick/minimagick] gem. MiniMagick requires
|
|
@@ -24,6 +17,8 @@ module ActiveStorage
|
|
|
24
17
|
return {}
|
|
25
18
|
end
|
|
26
19
|
|
|
20
|
+
ActiveStorage.require_securable_mini_magick!
|
|
21
|
+
|
|
27
22
|
download_blob_to_tempfile do |file|
|
|
28
23
|
image = instrument("mini_magick") do
|
|
29
24
|
MiniMagick::Image.new(file.path)
|
|
@@ -140,9 +140,12 @@ module ActiveStorage
|
|
|
140
140
|
"-show_streams",
|
|
141
141
|
"-show_format",
|
|
142
142
|
"-v", "error",
|
|
143
|
+
*ActiveStorage.ffmpeg_format_whitelist_arguments,
|
|
143
144
|
file.path
|
|
144
145
|
]) do |output|
|
|
145
146
|
JSON.parse(output.read)
|
|
147
|
+
end.tap do
|
|
148
|
+
logger.warn "Video analysis failed because ffprobe exited with status #{$?.exitstatus}. The file may be corrupt, or in a format outside config.active_storage.ffmpeg_allowed_formats." unless $?.success?
|
|
146
149
|
end
|
|
147
150
|
end
|
|
148
151
|
rescue Errno::ENOENT
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
module ActiveStorage
|
|
4
4
|
class Attached::Changes::CreateMany # :nodoc:
|
|
5
|
-
attr_reader :name, :
|
|
5
|
+
attr_reader :name, :attachables, :pending_uploads
|
|
6
|
+
attr_accessor :record
|
|
6
7
|
|
|
7
8
|
def initialize(name, record, attachables, pending_uploads: [])
|
|
8
9
|
@name, @record, @attachables = name, record, Array(attachables)
|
|
@@ -5,7 +5,8 @@ require "action_dispatch/http/upload"
|
|
|
5
5
|
|
|
6
6
|
module ActiveStorage
|
|
7
7
|
class Attached::Changes::CreateOne # :nodoc:
|
|
8
|
-
attr_reader :name, :
|
|
8
|
+
attr_reader :name, :attachable
|
|
9
|
+
attr_accessor :record
|
|
9
10
|
|
|
10
11
|
def initialize(name, record, attachable)
|
|
11
12
|
@name, @record, @attachable = name, record, attachable
|
|
@@ -75,7 +75,7 @@ module ActiveStorage
|
|
|
75
75
|
# The +:dependent+ option defaults to +:purge_later+. This means the attachment will be
|
|
76
76
|
# purged (i.e. destroyed) in the background whenever the record is destroyed.
|
|
77
77
|
# If an ActiveJob::Backend queue adapter is not set in the application set it to
|
|
78
|
-
#
|
|
78
|
+
# +:purge+ instead.
|
|
79
79
|
#
|
|
80
80
|
# If you need the attachment to use a service which differs from the globally configured one,
|
|
81
81
|
# pass the +:service+ option. For example:
|
|
@@ -177,7 +177,7 @@ module ActiveStorage
|
|
|
177
177
|
# The +:dependent+ option defaults to +:purge_later+. This means the attachments will be
|
|
178
178
|
# purged (i.e. destroyed) in the background whenever the record is destroyed.
|
|
179
179
|
# If an ActiveJob::Backend queue adapter is not set in the application set it to
|
|
180
|
-
#
|
|
180
|
+
# +:purge+ instead.
|
|
181
181
|
#
|
|
182
182
|
# If you need the attachment to use a service which differs from the globally configured one,
|
|
183
183
|
# pass the +:service+ option. For example:
|
|
@@ -278,6 +278,8 @@ module ActiveStorage
|
|
|
278
278
|
end
|
|
279
279
|
end
|
|
280
280
|
|
|
281
|
+
attr_writer :attachment_changes # :nodoc:
|
|
282
|
+
|
|
281
283
|
def attachment_changes # :nodoc:
|
|
282
284
|
@attachment_changes ||= {}
|
|
283
285
|
end
|
|
@@ -295,5 +297,14 @@ module ActiveStorage
|
|
|
295
297
|
def reload(*) # :nodoc:
|
|
296
298
|
super.tap { @attachment_changes = nil }
|
|
297
299
|
end
|
|
300
|
+
|
|
301
|
+
def becomes(klass) # :nodoc:
|
|
302
|
+
super.tap do |became|
|
|
303
|
+
attachment_changes = @attachment_changes&.each_value do |change|
|
|
304
|
+
change.record = became
|
|
305
|
+
end
|
|
306
|
+
became.attachment_changes = attachment_changes
|
|
307
|
+
end
|
|
308
|
+
end
|
|
298
309
|
end
|
|
299
310
|
end
|
|
@@ -45,6 +45,12 @@ module ActiveStorage
|
|
|
45
45
|
!attached?
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
# Returns the attachment record's JSON representation, or +nil+ when no
|
|
49
|
+
# attachment is present.
|
|
50
|
+
def as_json(options = nil)
|
|
51
|
+
attached? ? attachment.as_json(options) : nil
|
|
52
|
+
end
|
|
53
|
+
|
|
48
54
|
# Attaches an +attachable+ to the record.
|
|
49
55
|
#
|
|
50
56
|
# If the record is persisted and unchanged, the attachment is saved to
|
|
@@ -29,6 +29,7 @@ module ActiveStorage
|
|
|
29
29
|
config.active_storage.paths = ActiveSupport::OrderedOptions.new
|
|
30
30
|
config.active_storage.queues = ActiveSupport::InheritableOptions.new
|
|
31
31
|
config.active_storage.precompile_assets = true
|
|
32
|
+
config.active_storage.ffmpeg_allowed_formats = ActiveStorage.ffmpeg_allowed_formats
|
|
32
33
|
|
|
33
34
|
config.active_storage.variable_content_types = %w(
|
|
34
35
|
image/png
|
|
@@ -92,6 +93,10 @@ module ActiveStorage
|
|
|
92
93
|
ActiveStorage.previewers = app.config.active_storage.previewers || []
|
|
93
94
|
ActiveStorage.analyzers = app.config.active_storage.analyzers || []
|
|
94
95
|
|
|
96
|
+
if ActiveStorage::MINIMAGICK_AVAILABLE && !ActiveStorage::MINIMAGICK_UNSECURABLE
|
|
97
|
+
ActiveStorage::ImageMagick.apply_policy
|
|
98
|
+
end
|
|
99
|
+
|
|
95
100
|
begin
|
|
96
101
|
ActiveStorage.variant_transformer =
|
|
97
102
|
case ActiveStorage.variant_processor
|
|
@@ -115,6 +120,16 @@ module ActiveStorage
|
|
|
115
120
|
Please add `gem "image_processing", "~> 1.2"` to your Gemfile
|
|
116
121
|
or set `config.active_storage.variant_processor = :disabled`.
|
|
117
122
|
WARNING
|
|
123
|
+
when /ruby-vips/
|
|
124
|
+
ActiveStorage.logger.warn <<~WARNING.squish
|
|
125
|
+
Generating image variants with libvips requires the ruby-vips gem.
|
|
126
|
+
Please add `gem "ruby-vips", "~> 2.3"` to your Gemfile.
|
|
127
|
+
WARNING
|
|
128
|
+
when /mini_magick/
|
|
129
|
+
ActiveStorage.logger.warn <<~WARNING.squish
|
|
130
|
+
Generating image variants with ImageMagick requires the mini_magick gem.
|
|
131
|
+
Please add `gem "mini_magick", "~> 5.1"` to your Gemfile.
|
|
132
|
+
WARNING
|
|
118
133
|
else
|
|
119
134
|
raise
|
|
120
135
|
end
|
|
@@ -148,6 +163,7 @@ module ActiveStorage
|
|
|
148
163
|
ActiveStorage.content_types_allowed_inline = app.config.active_storage.content_types_allowed_inline || []
|
|
149
164
|
ActiveStorage.binary_content_type = app.config.active_storage.binary_content_type || "application/octet-stream"
|
|
150
165
|
ActiveStorage.video_preview_arguments = app.config.active_storage.video_preview_arguments || "-y -vframes 1 -f image2"
|
|
166
|
+
ActiveStorage.ffmpeg_allowed_formats = app.config.active_storage.ffmpeg_allowed_formats
|
|
151
167
|
ActiveStorage.track_variants = app.config.active_storage.track_variants || false
|
|
152
168
|
ActiveStorage.streaming_chunk_max_size = app.config.active_storage.streaming_chunk_max_size || 100.megabytes
|
|
153
169
|
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Active Storage's ImageMagick security policy. Applied in addition to the host's policy.xml,
|
|
3
|
+
through MAGICK_CONFIGURE_PATH, to every ImageMagick process MiniMagick spawns.
|
|
4
|
+
|
|
5
|
+
This file must work under both ImageMagick 6 and ImageMagick 7. Use the "coder", "delegate"
|
|
6
|
+
and "path" domains, which every release of both honors. A domain one release does not know,
|
|
7
|
+
such as "module" on older ImageMagick 6 releases, is ignored rather than rejected.
|
|
8
|
+
|
|
9
|
+
ImageMagick picks a coder from the file's content, and several coders name the same underlying
|
|
10
|
+
reader through different tokens (PS, EPS, EPI, EPSF, EPSI, EPT; PDF, AI, EPDF, PDFA, POCKETMOD). A
|
|
11
|
+
coder rule matches one token, so every token is denied by coder.
|
|
12
|
+
|
|
13
|
+
Do not put a backtick anywhere in this file. ImageMagick's tokenizer treats a backtick as an
|
|
14
|
+
opening quote and silently drops every rule up to the next apostrophe.
|
|
15
|
+
-->
|
|
16
|
+
<policymap>
|
|
17
|
+
<!-- Scripting coder that reads and writes files named inside the image. -->
|
|
18
|
+
<policy domain="coder" rights="none" pattern="MSL"/>
|
|
19
|
+
|
|
20
|
+
<!-- Coders that read a file, or delete one, other than the image being processed. -->
|
|
21
|
+
<policy domain="coder" rights="none" pattern="EPHEMERAL"/>
|
|
22
|
+
<policy domain="coder" rights="none" pattern="TEXT"/>
|
|
23
|
+
|
|
24
|
+
<!-- Coder that reads back a pixel cache from a file the image header names. -->
|
|
25
|
+
<policy domain="coder" rights="none" pattern="MPC"/>
|
|
26
|
+
|
|
27
|
+
<!-- Coders that display to a screen. -->
|
|
28
|
+
<policy domain="coder" rights="none" pattern="SHOW"/>
|
|
29
|
+
<policy domain="coder" rights="none" pattern="WIN"/>
|
|
30
|
+
<policy domain="coder" rights="none" pattern="PLT"/>
|
|
31
|
+
|
|
32
|
+
<!-- Coders that read a reference from outside the image, remote or local. FILE reads file://. -->
|
|
33
|
+
<policy domain="coder" rights="none" pattern="URL"/>
|
|
34
|
+
<policy domain="coder" rights="none" pattern="HTTP"/>
|
|
35
|
+
<policy domain="coder" rights="none" pattern="HTTPS"/>
|
|
36
|
+
<policy domain="coder" rights="none" pattern="FTP"/>
|
|
37
|
+
<policy domain="coder" rights="none" pattern="FILE"/>
|
|
38
|
+
|
|
39
|
+
<!-- Interpreters that read and write files of their own. Ghostscript backs the PS and PDF
|
|
40
|
+
coders and their token aliases; GhostXPS and GhostPCL back XPS and PCL. The "gs" delegate
|
|
41
|
+
covers ImageMagick builds that run Ghostscript as an external command, and the coder rules
|
|
42
|
+
cover builds that link it in-process, where the delegate rule never applies. An
|
|
43
|
+
application that transforms PostScript or PDF through ImageMagick must allow the "gs"
|
|
44
|
+
delegate, and the coders it uses, again in the host's policy.xml. -->
|
|
45
|
+
<policy domain="delegate" rights="none" pattern="gs"/>
|
|
46
|
+
<policy domain="coder" rights="none" pattern="PS"/>
|
|
47
|
+
<policy domain="coder" rights="none" pattern="PS2"/>
|
|
48
|
+
<policy domain="coder" rights="none" pattern="PS3"/>
|
|
49
|
+
<policy domain="coder" rights="none" pattern="EPS"/>
|
|
50
|
+
<policy domain="coder" rights="none" pattern="EPS2"/>
|
|
51
|
+
<policy domain="coder" rights="none" pattern="EPS3"/>
|
|
52
|
+
<policy domain="coder" rights="none" pattern="EPI"/>
|
|
53
|
+
<policy domain="coder" rights="none" pattern="EPSF"/>
|
|
54
|
+
<policy domain="coder" rights="none" pattern="EPSI"/>
|
|
55
|
+
<policy domain="coder" rights="none" pattern="EPT"/>
|
|
56
|
+
<policy domain="coder" rights="none" pattern="EPT2"/>
|
|
57
|
+
<policy domain="coder" rights="none" pattern="EPT3"/>
|
|
58
|
+
<policy domain="coder" rights="none" pattern="PDF"/>
|
|
59
|
+
<policy domain="coder" rights="none" pattern="AI"/>
|
|
60
|
+
<policy domain="coder" rights="none" pattern="EPDF"/>
|
|
61
|
+
<policy domain="coder" rights="none" pattern="PDFA"/>
|
|
62
|
+
<policy domain="coder" rights="none" pattern="POCKETMOD"/>
|
|
63
|
+
<policy domain="coder" rights="none" pattern="XPS"/>
|
|
64
|
+
<policy domain="coder" rights="none" pattern="PCL"/>
|
|
65
|
+
|
|
66
|
+
<!-- Indirect reads such as text:@/etc/passwd, which substitute a file for an argument. -->
|
|
67
|
+
<policy domain="path" rights="none" pattern="@*"/>
|
|
68
|
+
</policymap>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# :markup: markdown
|
|
4
|
+
|
|
5
|
+
require "active_storage"
|
|
6
|
+
require "active_support/core_ext/object/blank"
|
|
7
|
+
require "active_support/core_ext/string/filters"
|
|
8
|
+
|
|
9
|
+
begin
|
|
10
|
+
gem "mini_magick"
|
|
11
|
+
require "mini_magick"
|
|
12
|
+
ActiveStorage::MINIMAGICK_AVAILABLE = true # :nodoc:
|
|
13
|
+
rescue LoadError => error
|
|
14
|
+
ActiveStorage::MINIMAGICK_AVAILABLE = false # :nodoc:
|
|
15
|
+
raise error unless error.message.include?("mini_magick")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
module ActiveStorage
|
|
19
|
+
# Adds Active Storage's ImageMagick security policy to every ImageMagick process MiniMagick spawns.
|
|
20
|
+
#
|
|
21
|
+
# ImageMagick reads every `policy.xml` on its configuration search path and applies all of them,
|
|
22
|
+
# so the shipped policy adds to the operator's policy rather than replacing it. `MAGICK_CONFIGURE_PATH`
|
|
23
|
+
# prepends to that search path; a value the operator has already set, in the environment or in
|
|
24
|
+
# `MiniMagick.cli_env`, is kept after the shipped directory.
|
|
25
|
+
module ImageMagick
|
|
26
|
+
POLICY_DIRECTORY = File.expand_path("image_magick", __dir__)
|
|
27
|
+
|
|
28
|
+
# Called when Active Storage loads, and again after the application initializes, so that a
|
|
29
|
+
# `MAGICK_CONFIGURE_PATH` or `MiniMagick.cli_env` set by an initializer or dotenv keeps the policy.
|
|
30
|
+
def self.apply_policy # :nodoc:
|
|
31
|
+
operator_paths = operator_paths(MiniMagick.cli_env["MAGICK_CONFIGURE_PATH"]).presence ||
|
|
32
|
+
operator_paths(ENV["MAGICK_CONFIGURE_PATH"])
|
|
33
|
+
|
|
34
|
+
MiniMagick.cli_env = MiniMagick.cli_env.merge("MAGICK_CONFIGURE_PATH" => configure_path(operator_paths)).freeze
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.configure_path(operator_path)
|
|
38
|
+
[ POLICY_DIRECTORY, *operator_paths(operator_path) ].join(File::PATH_SEPARATOR)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.operator_paths(path)
|
|
42
|
+
Array(path).flat_map { |entry| entry.split(File::PATH_SEPARATOR) } - [ POLICY_DIRECTORY, "" ]
|
|
43
|
+
end
|
|
44
|
+
private_class_method :operator_paths
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
ActiveStorage::MINIMAGICK_UNSECURABLE = ActiveStorage::MINIMAGICK_AVAILABLE && !MiniMagick.respond_to?(:cli_env=) # :nodoc:
|
|
49
|
+
|
|
50
|
+
module ActiveStorage
|
|
51
|
+
# Raises when the installed mini_magick cannot apply the shipped ImageMagick security policy.
|
|
52
|
+
# Called before Active Storage hands untrusted content to ImageMagick.
|
|
53
|
+
def self.require_securable_mini_magick! # :nodoc:
|
|
54
|
+
if MINIMAGICK_UNSECURABLE
|
|
55
|
+
raise <<~ERROR.squish
|
|
56
|
+
Active Storage's ImageMagick security policy requires mini_magick 5.1 or later. Please add
|
|
57
|
+
`gem "mini_magick", "~> 5.1"` to your Gemfile, or use the :vips variant processor.
|
|
58
|
+
ERROR
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
ActiveStorage::ImageMagick.apply_policy if ActiveStorage::MINIMAGICK_AVAILABLE && !ActiveStorage::MINIMAGICK_UNSECURABLE
|
|
@@ -30,7 +30,7 @@ module ActiveStorage
|
|
|
30
30
|
|
|
31
31
|
private
|
|
32
32
|
def draw_relevant_frame_from(file, &block)
|
|
33
|
-
draw self.class.ffmpeg_path, "-i", file.path, *Shellwords.split(ActiveStorage.video_preview_arguments), "-", &block
|
|
33
|
+
draw self.class.ffmpeg_path, *ActiveStorage.ffmpeg_format_whitelist_arguments, "-i", file.path, *Shellwords.split(ActiveStorage.video_preview_arguments), "-", &block
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
end
|
|
@@ -89,27 +89,16 @@ module ActiveStorage
|
|
|
89
89
|
end
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
def url_for_direct_upload(key, expires_in:, checksum:, custom_metadata: {}, **)
|
|
92
|
+
def url_for_direct_upload(key, expires_in:, checksum:, content_length:, custom_metadata: {}, **)
|
|
93
93
|
instrument :url, key: key do |payload|
|
|
94
|
-
headers
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if @config[:cache_control].present?
|
|
98
|
-
headers["Cache-Control"] = @config[:cache_control]
|
|
99
|
-
# v2 signing doesn't support non `x-goog-` headers. Only switch to v4 signing
|
|
100
|
-
# if necessary for back-compat; v4 limits the expiration of the URL to 7 days
|
|
101
|
-
# whereas v2 has no limit
|
|
102
|
-
version = :v4
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
headers.merge!(custom_metadata_headers(custom_metadata))
|
|
106
|
-
|
|
94
|
+
# V2 signatures bind the Content-Type (empty) and Content-MD5 headers. GCS leaves headers
|
|
95
|
+
# other than x-goog-* out of V2 signatures, so the client sends Cache-Control unsigned.
|
|
107
96
|
args = {
|
|
108
97
|
content_md5: checksum,
|
|
109
98
|
expires: expires_in,
|
|
110
|
-
headers:
|
|
99
|
+
headers: { "x-goog-content-length-range" => content_length_range(content_length), **custom_metadata_headers(custom_metadata) },
|
|
111
100
|
method: "PUT",
|
|
112
|
-
version:
|
|
101
|
+
version: :v2,
|
|
113
102
|
}
|
|
114
103
|
|
|
115
104
|
if @config[:iam]
|
|
@@ -125,10 +114,10 @@ module ActiveStorage
|
|
|
125
114
|
end
|
|
126
115
|
end
|
|
127
116
|
|
|
128
|
-
def headers_for_direct_upload(key, checksum:, filename: nil, disposition: nil, custom_metadata: {}, **)
|
|
117
|
+
def headers_for_direct_upload(key, checksum:, content_length:, filename: nil, disposition: nil, custom_metadata: {}, **)
|
|
129
118
|
content_disposition = content_disposition_with(type: disposition, filename: filename) if filename
|
|
130
119
|
|
|
131
|
-
headers = { "Content-MD5" => checksum, "Content-Disposition" => content_disposition, **custom_metadata_headers(custom_metadata) }
|
|
120
|
+
headers = { "Content-MD5" => checksum, "Content-Disposition" => content_disposition, "x-goog-content-length-range" => content_length_range(content_length), **custom_metadata_headers(custom_metadata) }
|
|
132
121
|
if @config[:cache_control].present?
|
|
133
122
|
headers["Cache-Control"] = @config[:cache_control]
|
|
134
123
|
end
|
|
@@ -238,5 +227,9 @@ module ActiveStorage
|
|
|
238
227
|
def custom_metadata_headers(metadata)
|
|
239
228
|
metadata.transform_keys { |key| "x-goog-meta-#{key}" }
|
|
240
229
|
end
|
|
230
|
+
|
|
231
|
+
def content_length_range(content_length)
|
|
232
|
+
"#{content_length},#{content_length}"
|
|
233
|
+
end
|
|
241
234
|
end
|
|
242
235
|
end
|
|
@@ -7,7 +7,7 @@ module ActiveStorage
|
|
|
7
7
|
# Wraps a set of mirror services and provides a single ActiveStorage::Service object that will all
|
|
8
8
|
# have the files uploaded to them. A +primary+ service is designated to answer calls to:
|
|
9
9
|
# * +download+
|
|
10
|
-
# * +
|
|
10
|
+
# * +exist?+
|
|
11
11
|
# * +url+
|
|
12
12
|
# * +url_for_direct_upload+
|
|
13
13
|
# * +headers_for_direct_upload+
|
|
@@ -66,10 +66,12 @@ module ActiveStorage
|
|
|
66
66
|
def mirror(key, checksum:)
|
|
67
67
|
instrument :mirror, key: key, checksum: checksum do
|
|
68
68
|
if (mirrors_in_need_of_mirroring = mirrors.select { |service| !service.exist?(key) }).any?
|
|
69
|
-
|
|
69
|
+
metadata = ActiveStorage::Blob.find_by(key: key)&.service_metadata || {}
|
|
70
|
+
|
|
71
|
+
primary.open(key, checksum: checksum, verify: checksum.present?) do |io|
|
|
70
72
|
mirrors_in_need_of_mirroring.each do |service|
|
|
71
73
|
io.rewind
|
|
72
|
-
service.upload key, io, checksum: checksum
|
|
74
|
+
service.upload key, io, checksum: checksum, **metadata
|
|
73
75
|
end
|
|
74
76
|
end
|
|
75
77
|
end
|
data/lib/active_storage.rb
CHANGED
|
@@ -34,6 +34,7 @@ require "active_storage/deprecator"
|
|
|
34
34
|
require "active_storage/errors"
|
|
35
35
|
|
|
36
36
|
require "marcel"
|
|
37
|
+
require "openssl"
|
|
37
38
|
|
|
38
39
|
# :markup: markdown
|
|
39
40
|
# :include: ../README.md
|
|
@@ -358,6 +359,9 @@ module ActiveStorage
|
|
|
358
359
|
mattr_accessor :touch_attachment_records, default: true
|
|
359
360
|
mattr_accessor :urls_expire_in
|
|
360
361
|
|
|
362
|
+
# Configures the mount point for the default Active Storage routes. Accepts any
|
|
363
|
+
# value supported by `scope`, such as a string path prefix or a hash of routing
|
|
364
|
+
# options.
|
|
361
365
|
mattr_accessor :routes_prefix, default: "/rails/active_storage"
|
|
362
366
|
mattr_accessor :draw_routes, default: true
|
|
363
367
|
mattr_accessor :resolve_model_to_route, default: :rails_storage_redirect
|
|
@@ -378,6 +382,12 @@ module ActiveStorage
|
|
|
378
382
|
|
|
379
383
|
mattr_accessor :video_preview_arguments, default: "-y -vframes 1 -f image2"
|
|
380
384
|
|
|
385
|
+
mattr_accessor :ffmpeg_allowed_formats, default: %w[ mov matroska avi mpeg mpegts flv asf ogg mp3 wav flac aac aiff caf ].freeze
|
|
386
|
+
|
|
387
|
+
def self.ffmpeg_format_whitelist_arguments # :nodoc:
|
|
388
|
+
[ "-format_whitelist", Array(ffmpeg_allowed_formats).join(",") ] unless ffmpeg_allowed_formats.nil?
|
|
389
|
+
end
|
|
390
|
+
|
|
381
391
|
module Transformers
|
|
382
392
|
extend ActiveSupport::Autoload
|
|
383
393
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activestorage
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 8.1.
|
|
4
|
+
version: 8.1.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Heinemeier Hansson
|
|
@@ -15,56 +15,56 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 8.1.
|
|
18
|
+
version: 8.1.4.1
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 8.1.
|
|
25
|
+
version: 8.1.4.1
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: actionpack
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
30
|
- - '='
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 8.1.
|
|
32
|
+
version: 8.1.4.1
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - '='
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: 8.1.
|
|
39
|
+
version: 8.1.4.1
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: activejob
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
43
43
|
requirements:
|
|
44
44
|
- - '='
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: 8.1.
|
|
46
|
+
version: 8.1.4.1
|
|
47
47
|
type: :runtime
|
|
48
48
|
prerelease: false
|
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
51
|
- - '='
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: 8.1.
|
|
53
|
+
version: 8.1.4.1
|
|
54
54
|
- !ruby/object:Gem::Dependency
|
|
55
55
|
name: activerecord
|
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
|
57
57
|
requirements:
|
|
58
58
|
- - '='
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: 8.1.
|
|
60
|
+
version: 8.1.4.1
|
|
61
61
|
type: :runtime
|
|
62
62
|
prerelease: false
|
|
63
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
64
64
|
requirements:
|
|
65
65
|
- - '='
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: 8.1.
|
|
67
|
+
version: 8.1.4.1
|
|
68
68
|
- !ruby/object:Gem::Dependency
|
|
69
69
|
name: marcel
|
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -166,6 +166,8 @@ files:
|
|
|
166
166
|
- lib/active_storage/errors.rb
|
|
167
167
|
- lib/active_storage/fixture_set.rb
|
|
168
168
|
- lib/active_storage/gem_version.rb
|
|
169
|
+
- lib/active_storage/image_magick.rb
|
|
170
|
+
- lib/active_storage/image_magick/policy.xml
|
|
169
171
|
- lib/active_storage/log_subscriber.rb
|
|
170
172
|
- lib/active_storage/previewer.rb
|
|
171
173
|
- lib/active_storage/previewer/mupdf_previewer.rb
|
|
@@ -193,10 +195,10 @@ licenses:
|
|
|
193
195
|
- MIT
|
|
194
196
|
metadata:
|
|
195
197
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
|
196
|
-
changelog_uri: https://github.com/rails/rails/blob/v8.1.
|
|
197
|
-
documentation_uri: https://api.rubyonrails.org/v8.1.
|
|
198
|
+
changelog_uri: https://github.com/rails/rails/blob/v8.1.4.1/activestorage/CHANGELOG.md
|
|
199
|
+
documentation_uri: https://api.rubyonrails.org/v8.1.4.1/
|
|
198
200
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
|
199
|
-
source_code_uri: https://github.com/rails/rails/tree/v8.1.
|
|
201
|
+
source_code_uri: https://github.com/rails/rails/tree/v8.1.4.1/activestorage
|
|
200
202
|
rubygems_mfa_required: 'true'
|
|
201
203
|
rdoc_options: []
|
|
202
204
|
require_paths:
|
|
@@ -212,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
212
214
|
- !ruby/object:Gem::Version
|
|
213
215
|
version: '0'
|
|
214
216
|
requirements: []
|
|
215
|
-
rubygems_version: 4.0.
|
|
217
|
+
rubygems_version: 4.0.20
|
|
216
218
|
specification_version: 4
|
|
217
219
|
summary: Local and cloud file storage framework.
|
|
218
220
|
test_files: []
|