activestorage 7.2.4 → 8.0.5.2
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 +168 -85
- data/README.md +2 -2
- data/app/assets/javascripts/activestorage.esm.js +1 -1
- data/app/assets/javascripts/activestorage.js +1 -0
- data/app/controllers/active_storage/direct_uploads_controller.rb +1 -1
- data/app/controllers/concerns/active_storage/streaming.rb +14 -0
- data/app/javascript/activestorage/index.js +2 -1
- data/app/models/active_storage/blob/representable.rb +5 -5
- data/app/models/active_storage/blob.rb +28 -9
- data/app/models/active_storage/filename.rb +5 -4
- data/app/models/active_storage/variant.rb +6 -6
- data/lib/active_storage/analyzer/audio_analyzer.rb +3 -0
- data/lib/active_storage/analyzer/image_analyzer/image_magick.rb +4 -0
- data/lib/active_storage/analyzer/image_analyzer/vips.rb +1 -1
- data/lib/active_storage/analyzer/video_analyzer.rb +3 -0
- data/lib/active_storage/attached/model.rb +20 -16
- data/lib/active_storage/engine.rb +9 -0
- data/lib/active_storage/gem_version.rb +4 -4
- 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/service/azure_storage_service.rb +7 -0
- data/lib/active_storage/service/gcs_service.rb +11 -18
- data/lib/active_storage/service/mirror_service.rb +12 -3
- data/lib/active_storage.rb +6 -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: 4a80631946acf9e13e4ec23935d8af2716be34402fde6e152b7729d265b7143f
|
|
4
|
+
data.tar.gz: 9f88ee639a12ee64597157ffb234cb6f1c1795c977d8d032a9b898056a8945dd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e115b9bdf1dc8dc6a8b1b4308472be20ca9b8fb8f312ce6be4a953e1b193398b766acfb06e29fd5f91d3182dc93d988cb2a30b71b0a304151f44aea99947c433
|
|
7
|
+
data.tar.gz: f5674d75df03fda65bbfc9d57853732c1636ca2fd4d4ade3badd1ac0d62e799c17dde356104effa419865136e4d56a5d73fd2233e234349015d28f44600ee0e1
|
data/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,128 @@
|
|
|
1
|
-
## Rails
|
|
1
|
+
## Rails 8.0.5.2 (November 03, 2026) ##
|
|
2
2
|
|
|
3
|
-
*
|
|
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*
|
|
4
79
|
|
|
80
|
+
* Sign GCS direct uploads with V2 when `cache_control` is set.
|
|
5
81
|
|
|
6
|
-
|
|
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.0.5.1 (July 29, 2026) ##
|
|
7
126
|
|
|
8
127
|
* Disable libvips's unfuzzed image loaders and savers.
|
|
9
128
|
|
|
@@ -46,7 +165,15 @@
|
|
|
46
165
|
|
|
47
166
|
*Mike Dalessio*
|
|
48
167
|
|
|
49
|
-
|
|
168
|
+
|
|
169
|
+
## Rails 8.0.5 (March 24, 2026) ##
|
|
170
|
+
|
|
171
|
+
* Fix `ActiveStorage::Blob` content type predicate methods to handle `nil`.
|
|
172
|
+
|
|
173
|
+
*Daichi KUDO*
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
## Rails 8.0.4.1 (March 23, 2026) ##
|
|
50
177
|
|
|
51
178
|
* Filter user supplied metadata in DirectUploadController
|
|
52
179
|
|
|
@@ -97,26 +224,23 @@
|
|
|
97
224
|
*Mike Dalessio*
|
|
98
225
|
|
|
99
226
|
|
|
100
|
-
## Rails
|
|
227
|
+
## Rails 8.0.4 (October 28, 2025) ##
|
|
101
228
|
|
|
102
|
-
*
|
|
229
|
+
* No changes.
|
|
103
230
|
|
|
104
|
-
*fatkodima*
|
|
105
231
|
|
|
106
|
-
|
|
232
|
+
## Rails 8.0.3 (September 22, 2025) ##
|
|
107
233
|
|
|
108
|
-
|
|
109
|
-
its dirty attributes reset, preventing your `after commit` callbacks
|
|
110
|
-
on that record to behave as expected.
|
|
234
|
+
* Address deprecation of `Aws::S3::Object#upload_stream` in `ActiveStorage::Service::S3Service`.
|
|
111
235
|
|
|
112
|
-
|
|
113
|
-
and is supposed to be internal. Active Storage Attachment will continue
|
|
114
|
-
to be autosaved (through a different relation).
|
|
236
|
+
*Joshua Young*
|
|
115
237
|
|
|
116
|
-
|
|
238
|
+
* Fix `config.active_storage.touch_attachment_records` to work with eager loading.
|
|
239
|
+
|
|
240
|
+
*fatkodima*
|
|
117
241
|
|
|
118
242
|
|
|
119
|
-
## Rails
|
|
243
|
+
## Rails 8.0.2.1 (August 13, 2025) ##
|
|
120
244
|
|
|
121
245
|
* Remove dangerous transformations
|
|
122
246
|
|
|
@@ -124,107 +248,66 @@
|
|
|
124
248
|
|
|
125
249
|
*Zack Deveau*
|
|
126
250
|
|
|
251
|
+
## Rails 8.0.2 (March 12, 2025) ##
|
|
127
252
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
* No changes.
|
|
253
|
+
* A Blob will no longer autosave associated Attachment.
|
|
131
254
|
|
|
255
|
+
This fixes an issue where a record with an attachment would have
|
|
256
|
+
its dirty attributes reset, preventing your `after commit` callbacks
|
|
257
|
+
on that record to behave as expected.
|
|
132
258
|
|
|
133
|
-
|
|
259
|
+
Note that this change doesn't require any changes on your application
|
|
260
|
+
and is supposed to be internal. Active Storage Attachment will continue
|
|
261
|
+
to be autosaved (through a different relation).
|
|
134
262
|
|
|
135
|
-
*
|
|
263
|
+
*Edouard-chin*
|
|
136
264
|
|
|
137
265
|
|
|
138
|
-
## Rails
|
|
266
|
+
## Rails 8.0.1 (December 13, 2024) ##
|
|
139
267
|
|
|
140
268
|
* No changes.
|
|
141
269
|
|
|
142
270
|
|
|
143
|
-
## Rails
|
|
271
|
+
## Rails 8.0.0.1 (December 10, 2024) ##
|
|
144
272
|
|
|
145
273
|
* No changes.
|
|
146
274
|
|
|
147
275
|
|
|
148
|
-
## Rails
|
|
276
|
+
## Rails 8.0.0 (November 07, 2024) ##
|
|
149
277
|
|
|
150
278
|
* No changes.
|
|
151
279
|
|
|
152
280
|
|
|
153
|
-
## Rails
|
|
154
|
-
|
|
155
|
-
* Remove deprecated `config.active_storage.silence_invalid_content_types_warning`.
|
|
156
|
-
|
|
157
|
-
*Rafael Mendonça França*
|
|
158
|
-
|
|
159
|
-
* Remove deprecated `config.active_storage.replace_on_assign_to_many`.
|
|
160
|
-
|
|
161
|
-
*Rafael Mendonça França*
|
|
162
|
-
|
|
163
|
-
* Add support for custom `key` in `ActiveStorage::Blob#compose`.
|
|
164
|
-
|
|
165
|
-
*Elvin Efendiev*
|
|
166
|
-
|
|
167
|
-
* Add `image/webp` to `config.active_storage.web_image_content_types` when `load_defaults "7.2"`
|
|
168
|
-
is set.
|
|
281
|
+
## Rails 8.0.0.rc2 (October 30, 2024) ##
|
|
169
282
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
* Fix JSON-encoding of `ActiveStorage::Filename` instances.
|
|
173
|
-
|
|
174
|
-
*Jonathan del Strother*
|
|
175
|
-
|
|
176
|
-
* Fix N+1 query when fetching preview images for non-image assets.
|
|
177
|
-
|
|
178
|
-
*Aaron Patterson & Justin Searls*
|
|
179
|
-
|
|
180
|
-
* Fix all Active Storage database related models to respect
|
|
181
|
-
`ActiveRecord::Base.table_name_prefix` configuration.
|
|
182
|
-
|
|
183
|
-
*Chedli Bourguiba*
|
|
184
|
-
|
|
185
|
-
* Fix `ActiveStorage::Representations::ProxyController` not returning the proper
|
|
186
|
-
preview image variant for previewable files.
|
|
187
|
-
|
|
188
|
-
*Chedli Bourguiba*
|
|
189
|
-
|
|
190
|
-
* Fix `ActiveStorage::Representations::ProxyController` to proxy untracked
|
|
191
|
-
variants.
|
|
283
|
+
* No changes.
|
|
192
284
|
|
|
193
|
-
*Chedli Bourguiba*
|
|
194
285
|
|
|
195
|
-
|
|
196
|
-
for blobs that are not representable.
|
|
286
|
+
## Rails 8.0.0.rc1 (October 19, 2024) ##
|
|
197
287
|
|
|
198
|
-
|
|
288
|
+
* No changes.
|
|
199
289
|
|
|
200
|
-
* Prevent `ActiveStorage::Blob#preview` to generate a variant if an empty variation is passed.
|
|
201
290
|
|
|
202
|
-
|
|
203
|
-
image instead of generating a variant with the exact same dimensions.
|
|
291
|
+
## Rails 8.0.0.beta1 (September 26, 2024) ##
|
|
204
292
|
|
|
205
|
-
|
|
293
|
+
* Deprecate `ActiveStorage::Service::AzureStorageService`.
|
|
206
294
|
|
|
207
|
-
*
|
|
295
|
+
*zzak*
|
|
208
296
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
Previously, the `:thumb` variant would not be generated until a further call
|
|
212
|
-
to e.g. `processed.url`.
|
|
297
|
+
* Improve `ActiveStorage::Filename#sanitized` method to handle special characters more effectively.
|
|
298
|
+
Replace the characters `"*?<>` with `-` if they exist in the Filename to match the Filename convention of Win OS.
|
|
213
299
|
|
|
214
|
-
*
|
|
300
|
+
*Luong Viet Dung(Martin)*
|
|
215
301
|
|
|
216
|
-
*
|
|
217
|
-
enabled and the variant of an Active Storage preview has already been
|
|
218
|
-
processed (for example, by calling `ActiveStorage::Preview#url`).
|
|
302
|
+
* Improve InvariableError, UnpreviewableError and UnrepresentableError message.
|
|
219
303
|
|
|
220
|
-
|
|
304
|
+
Include Blob ID and content_type in the messages.
|
|
221
305
|
|
|
222
|
-
*
|
|
306
|
+
*Petrik de Heus*
|
|
223
307
|
|
|
224
|
-
|
|
308
|
+
* Mark proxied files as `immutable` in their Cache-Control header
|
|
225
309
|
|
|
226
|
-
*
|
|
310
|
+
*Nate Matykiewicz*
|
|
227
311
|
|
|
228
|
-
*Yogesh Khater*
|
|
229
312
|
|
|
230
|
-
Please check [7-
|
|
313
|
+
Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/activestorage/CHANGELOG.md) for previous changes.
|
data/README.md
CHANGED
|
@@ -73,7 +73,7 @@ end
|
|
|
73
73
|
```erb
|
|
74
74
|
<%= form_with model: @message, local: true do |form| %>
|
|
75
75
|
<%= form.text_field :title, placeholder: "Title" %><br>
|
|
76
|
-
<%= form.
|
|
76
|
+
<%= form.textarea :content %><br><br>
|
|
77
77
|
|
|
78
78
|
<%= form.file_field :images, multiple: true %><br>
|
|
79
79
|
<%= form.submit %>
|
|
@@ -88,7 +88,7 @@ class MessagesController < ApplicationController
|
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
def create
|
|
91
|
-
message = Message.create! params.
|
|
91
|
+
message = Message.create! params.expect(message: [ :title, :content, images: [] ])
|
|
92
92
|
redirect_to message
|
|
93
93
|
end
|
|
94
94
|
|
|
@@ -822,6 +822,7 @@
|
|
|
822
822
|
exports.DirectUpload = DirectUpload;
|
|
823
823
|
exports.DirectUploadController = DirectUploadController;
|
|
824
824
|
exports.DirectUploadsController = DirectUploadsController;
|
|
825
|
+
exports.dispatchEvent = dispatchEvent;
|
|
825
826
|
exports.start = start;
|
|
826
827
|
Object.defineProperty(exports, "__esModule", {
|
|
827
828
|
value: true
|
|
@@ -11,7 +11,7 @@ class ActiveStorage::DirectUploadsController < ActiveStorage::BaseController
|
|
|
11
11
|
|
|
12
12
|
private
|
|
13
13
|
def blob_args
|
|
14
|
-
params.
|
|
14
|
+
params.expect(blob: [:filename, :byte_size, :checksum, :content_type, metadata: {}]).to_h.symbolize_keys
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def direct_upload_json(blob)
|
|
@@ -68,6 +68,20 @@ module ActiveStorage::Streaming
|
|
|
68
68
|
blob.download do |chunk|
|
|
69
69
|
stream.write chunk
|
|
70
70
|
end
|
|
71
|
+
rescue ActiveStorage::FileNotFoundError
|
|
72
|
+
raise if response.committed?
|
|
73
|
+
|
|
74
|
+
expires_now
|
|
75
|
+
head :not_found
|
|
76
|
+
rescue
|
|
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
|
+
|
|
84
|
+
raise
|
|
71
85
|
end
|
|
72
86
|
end
|
|
73
87
|
end
|
|
@@ -2,7 +2,8 @@ import { start } from "./ujs"
|
|
|
2
2
|
import { DirectUpload } from "./direct_upload"
|
|
3
3
|
import { DirectUploadController } from "./direct_upload_controller"
|
|
4
4
|
import { DirectUploadsController } from "./direct_uploads_controller"
|
|
5
|
-
|
|
5
|
+
import { dispatchEvent } from "./helpers"
|
|
6
|
+
export { start, DirectUpload, DirectUploadController, DirectUploadsController, dispatchEvent }
|
|
6
7
|
|
|
7
8
|
function autostart() {
|
|
8
9
|
if (window.ActiveStorage) {
|
|
@@ -25,8 +25,8 @@ module ActiveStorage::Blob::Representable
|
|
|
25
25
|
#
|
|
26
26
|
# <%= image_tag Current.user.avatar.variant(resize_to_limit: [100, 100]) %>
|
|
27
27
|
#
|
|
28
|
-
# This will create a URL for that specific blob with that specific variant, which the ActiveStorage::
|
|
29
|
-
# can then produce on-demand.
|
|
28
|
+
# This will create a URL for that specific blob with that specific variant, which the ActiveStorage::Representations::ProxyController
|
|
29
|
+
# or ActiveStorage::Representations::RedirectController can then produce on-demand.
|
|
30
30
|
#
|
|
31
31
|
# Raises ActiveStorage::InvariableError if the variant processor cannot
|
|
32
32
|
# transform the blob. To determine whether a blob is variable, call
|
|
@@ -101,7 +101,7 @@ module ActiveStorage::Blob::Representable
|
|
|
101
101
|
if variable?
|
|
102
102
|
variant_class.new(self, ActiveStorage::Variation.wrap(transformations).default_to(default_variant_transformations))
|
|
103
103
|
else
|
|
104
|
-
raise ActiveStorage::InvariableError
|
|
104
|
+
raise ActiveStorage::InvariableError, "Can't transform blob with ID=#{id} and content_type=#{content_type}"
|
|
105
105
|
end
|
|
106
106
|
end
|
|
107
107
|
|
|
@@ -130,7 +130,7 @@ module ActiveStorage::Blob::Representable
|
|
|
130
130
|
if previewable?
|
|
131
131
|
ActiveStorage::Preview.new(self, transformations)
|
|
132
132
|
else
|
|
133
|
-
raise ActiveStorage::UnpreviewableError
|
|
133
|
+
raise ActiveStorage::UnpreviewableError, "No previewer found for blob with ID=#{id} and content_type=#{content_type}"
|
|
134
134
|
end
|
|
135
135
|
end
|
|
136
136
|
|
|
@@ -155,7 +155,7 @@ module ActiveStorage::Blob::Representable
|
|
|
155
155
|
when variable?
|
|
156
156
|
variant transformations
|
|
157
157
|
else
|
|
158
|
-
raise ActiveStorage::UnrepresentableError
|
|
158
|
+
raise ActiveStorage::UnrepresentableError, "No previewer found and can't transform blob with ID=#{id} and content_type=#{content_type}"
|
|
159
159
|
end
|
|
160
160
|
end
|
|
161
161
|
|
|
@@ -79,9 +79,8 @@ class ActiveStorage::Blob < ActiveStorage::Record
|
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
# Works like +find_signed+, but will raise an +ActiveSupport::MessageVerifier::InvalidSignature+
|
|
82
|
-
# exception if the +signed_id+ has either expired, has a purpose mismatch,
|
|
83
|
-
#
|
|
84
|
-
# the valid signed id can't find a record.
|
|
82
|
+
# exception if the +signed_id+ has either expired, has a purpose mismatch, or has been tampered with.
|
|
83
|
+
# It will also raise an +ActiveRecord::RecordNotFound+ exception if the valid signed id can't find a record.
|
|
85
84
|
def find_signed!(id, record: nil, purpose: :blob_id)
|
|
86
85
|
super(id, purpose: purpose)
|
|
87
86
|
end
|
|
@@ -211,22 +210,22 @@ class ActiveStorage::Blob < ActiveStorage::Record
|
|
|
211
210
|
|
|
212
211
|
# Returns true if the content_type of this blob is in the image range, like image/png.
|
|
213
212
|
def image?
|
|
214
|
-
content_type
|
|
213
|
+
content_type&.start_with?("image")
|
|
215
214
|
end
|
|
216
215
|
|
|
217
216
|
# Returns true if the content_type of this blob is in the audio range, like audio/mpeg.
|
|
218
217
|
def audio?
|
|
219
|
-
content_type
|
|
218
|
+
content_type&.start_with?("audio")
|
|
220
219
|
end
|
|
221
220
|
|
|
222
221
|
# Returns true if the content_type of this blob is in the video range, like video/mp4.
|
|
223
222
|
def video?
|
|
224
|
-
content_type
|
|
223
|
+
content_type&.start_with?("video")
|
|
225
224
|
end
|
|
226
225
|
|
|
227
226
|
# Returns true if the content_type of this blob is in the text range, like text/plain.
|
|
228
227
|
def text?
|
|
229
|
-
content_type
|
|
228
|
+
content_type&.start_with?("text")
|
|
230
229
|
end
|
|
231
230
|
|
|
232
231
|
# Returns the URL of the blob on the service. This returns a permanent URL for public files, and returns a
|
|
@@ -296,7 +295,8 @@ class ActiveStorage::Blob < ActiveStorage::Record
|
|
|
296
295
|
|
|
297
296
|
# Downloads the blob to a tempfile on disk. Yields the tempfile.
|
|
298
297
|
#
|
|
299
|
-
# The tempfile's name is prefixed with +ActiveStorage-+ and the blob's ID.
|
|
298
|
+
# The tempfile's name is prefixed with +ActiveStorage-+ and the blob's ID. It keeps the blob filename's
|
|
299
|
+
# extension when that extension denotes the blob's content type, and has no extension otherwise.
|
|
300
300
|
#
|
|
301
301
|
# By default, the tempfile is created in <tt>Dir.tmpdir</tt>. Pass +tmpdir:+ to create it in a different directory:
|
|
302
302
|
#
|
|
@@ -312,7 +312,7 @@ class ActiveStorage::Blob < ActiveStorage::Record
|
|
|
312
312
|
key,
|
|
313
313
|
checksum: checksum,
|
|
314
314
|
verify: !composed,
|
|
315
|
-
name: [ "ActiveStorage-#{id}-",
|
|
315
|
+
name: [ "ActiveStorage-#{id}-", tempfile_extension ],
|
|
316
316
|
tmpdir: tmpdir,
|
|
317
317
|
&block
|
|
318
318
|
)
|
|
@@ -351,6 +351,25 @@ class ActiveStorage::Blob < ActiveStorage::Record
|
|
|
351
351
|
end
|
|
352
352
|
|
|
353
353
|
private
|
|
354
|
+
# The extension is there for tools that cannot tell the type from the bytes (316d87e4: ImageMagick
|
|
355
|
+
# needs it for an SVG with no XML declaration), but some tools choose a decoder on it alone: FFmpeg
|
|
356
|
+
# runs a `.avs` file as an AviSynth script. So the uploaded extension is kept only when it denotes
|
|
357
|
+
# the blob's media type.
|
|
358
|
+
def tempfile_extension
|
|
359
|
+
extension = filename.extension_with_delimiter
|
|
360
|
+
return "" if extension.blank?
|
|
361
|
+
|
|
362
|
+
type_for_extension = Marcel::MimeType.for(name: filename.to_s)
|
|
363
|
+
return "" if type_for_extension == Marcel::MimeType::BINARY || type_for_extension != media_type
|
|
364
|
+
|
|
365
|
+
extension
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
# Marcel answers in canonical lowercase, so drop parameters and case before comparing.
|
|
369
|
+
def media_type
|
|
370
|
+
content_type.to_s.split(";").first.to_s.strip.downcase
|
|
371
|
+
end
|
|
372
|
+
|
|
354
373
|
def compute_checksum_in_chunks(io)
|
|
355
374
|
raise ArgumentError, "io must be rewindable" unless io.respond_to?(:rewind)
|
|
356
375
|
|
|
@@ -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}
|
|
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.
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
# Note that to create a variant it's necessary to download the entire blob file from the service. Because of this process,
|
|
23
23
|
# you also want to be considerate about when the variant is actually processed. You shouldn't be processing variants inline
|
|
24
24
|
# in a template, for example. Delay the processing to an on-demand controller, like the one provided in
|
|
25
|
-
# ActiveStorage::
|
|
25
|
+
# ActiveStorage::Representations::ProxyController and ActiveStorage::Representations::RedirectController.
|
|
26
26
|
#
|
|
27
27
|
# To refer to such a delayed on-demand variant, simply link to the variant through the resolved route provided
|
|
28
28
|
# by Active Storage like so:
|
|
29
29
|
#
|
|
30
30
|
# <%= image_tag Current.user.avatar.variant(resize_to_limit: [100, 100]) %>
|
|
31
31
|
#
|
|
32
|
-
# This will create a URL for that specific blob with that specific variant, which the ActiveStorage::
|
|
33
|
-
# can then produce on-demand.
|
|
32
|
+
# This will create a URL for that specific blob with that specific variant, which the ActiveStorage::Representations::ProxyController
|
|
33
|
+
# or ActiveStorage::Representations::RedirectController can then produce on-demand.
|
|
34
34
|
#
|
|
35
35
|
# When you do want to actually produce the variant needed, call +processed+. This will check that the variant
|
|
36
36
|
# has already been processed and uploaded to the service, and, if so, just return that. Otherwise it will perform
|
|
@@ -74,11 +74,11 @@ class ActiveStorage::Variant
|
|
|
74
74
|
"variants/#{blob.key}/#{OpenSSL::Digest::SHA256.hexdigest(variation.key)}"
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
# Returns the URL of the blob variant on the service. See
|
|
77
|
+
# Returns the URL of the blob variant on the service. See ActiveStorage::Blob#url for details.
|
|
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
|
-
# for a variant that points to the ActiveStorage::
|
|
81
|
-
# for its redirection.
|
|
80
|
+
# for a variant that points to the ActiveStorage::Representations::ProxyController or ActiveStorage::Representations::RedirectController,
|
|
81
|
+
# which in turn will use this +service_call+ 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,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "active_storage/image_magick"
|
|
4
|
+
|
|
3
5
|
module ActiveStorage
|
|
4
6
|
# This analyzer relies on the third-party {MiniMagick}[https://github.com/minimagick/minimagick] gem. MiniMagick requires
|
|
5
7
|
# the {ImageMagick}[http://www.imagemagick.org] system library.
|
|
@@ -17,6 +19,8 @@ module ActiveStorage
|
|
|
17
19
|
return {}
|
|
18
20
|
end
|
|
19
21
|
|
|
22
|
+
ActiveStorage.require_securable_mini_magick!
|
|
23
|
+
|
|
20
24
|
download_blob_to_tempfile do |file|
|
|
21
25
|
image = instrument("mini_magick") do
|
|
22
26
|
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
|
|
@@ -61,18 +61,16 @@ module ActiveStorage
|
|
|
61
61
|
# There is no column defined on the model side, Active Storage takes
|
|
62
62
|
# care of the mapping between your records and the attachment.
|
|
63
63
|
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
# User.with_attached_avatar
|
|
67
|
-
#
|
|
68
|
-
# Under the covers, this relationship is implemented as a +has_one+ association to a
|
|
69
|
-
# ActiveStorage::Attachment record and a +has_one-through+ association to a
|
|
64
|
+
# Under the covers, this relationship is implemented as a +has_one+ association to an
|
|
65
|
+
# ActiveStorage::Attachment record and a +has_one-through+ association to an
|
|
70
66
|
# ActiveStorage::Blob record. These associations are available as +avatar_attachment+
|
|
71
67
|
# and +avatar_blob+. But you shouldn't need to work with these associations directly in
|
|
72
68
|
# most circumstances.
|
|
73
69
|
#
|
|
74
|
-
#
|
|
75
|
-
#
|
|
70
|
+
# Instead, +has_one_attached+ generates an ActiveStorage::Attached::One proxy to
|
|
71
|
+
# provide access to the associations and factory methods, like +attach+:
|
|
72
|
+
#
|
|
73
|
+
# user.avatar.attach(uploaded_file)
|
|
76
74
|
#
|
|
77
75
|
# The +:dependent+ option defaults to +:purge_later+. This means the attachment will be
|
|
78
76
|
# purged (i.e. destroyed) in the background whenever the record is destroyed.
|
|
@@ -92,6 +90,10 @@ module ActiveStorage
|
|
|
92
90
|
# has_one_attached :avatar, service: ->(user) { user.in_europe_region? ? :s3_europe : :s3_usa }
|
|
93
91
|
# end
|
|
94
92
|
#
|
|
93
|
+
# To avoid N+1 queries, you can include the attached blobs in your query like so:
|
|
94
|
+
#
|
|
95
|
+
# User.with_attached_avatar
|
|
96
|
+
#
|
|
95
97
|
# If you need to enable +strict_loading+ to prevent lazy loading of attachment,
|
|
96
98
|
# pass the +:strict_loading+ option. You can do:
|
|
97
99
|
#
|
|
@@ -161,18 +163,16 @@ module ActiveStorage
|
|
|
161
163
|
# There are no columns defined on the model side, Active Storage takes
|
|
162
164
|
# care of the mapping between your records and the attachments.
|
|
163
165
|
#
|
|
164
|
-
#
|
|
165
|
-
#
|
|
166
|
-
# Gallery.where(user: Current.user).with_attached_photos
|
|
167
|
-
#
|
|
168
|
-
# Under the covers, this relationship is implemented as a +has_many+ association to a
|
|
169
|
-
# ActiveStorage::Attachment record and a +has_many-through+ association to a
|
|
166
|
+
# Under the covers, this relationship is implemented as a +has_many+ association to an
|
|
167
|
+
# ActiveStorage::Attachment record and a +has_many-through+ association to an
|
|
170
168
|
# ActiveStorage::Blob record. These associations are available as +photos_attachments+
|
|
171
169
|
# and +photos_blobs+. But you shouldn't need to work with these associations directly in
|
|
172
170
|
# most circumstances.
|
|
173
171
|
#
|
|
174
|
-
#
|
|
175
|
-
#
|
|
172
|
+
# Instead, +has_many_attached+ generates an ActiveStorage::Attached::Many proxy to
|
|
173
|
+
# provide access to the associations and factory methods, like +attach+:
|
|
174
|
+
#
|
|
175
|
+
# user.photos.attach(uploaded_file)
|
|
176
176
|
#
|
|
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.
|
|
@@ -192,6 +192,10 @@ module ActiveStorage
|
|
|
192
192
|
# has_many_attached :photos, service: ->(gallery) { gallery.personal? ? :personal_s3 : :s3 }
|
|
193
193
|
# end
|
|
194
194
|
#
|
|
195
|
+
# To avoid N+1 queries, you can include the attached blobs in your query like so:
|
|
196
|
+
#
|
|
197
|
+
# Gallery.where(user: Current.user).with_attached_photos
|
|
198
|
+
#
|
|
195
199
|
# If you need to enable +strict_loading+ to prevent lazy loading of attachments,
|
|
196
200
|
# pass the +:strict_loading+ option. You can do:
|
|
197
201
|
#
|
|
@@ -31,6 +31,7 @@ module ActiveStorage
|
|
|
31
31
|
config.active_storage.paths = ActiveSupport::OrderedOptions.new
|
|
32
32
|
config.active_storage.queues = ActiveSupport::InheritableOptions.new
|
|
33
33
|
config.active_storage.precompile_assets = true
|
|
34
|
+
config.active_storage.ffmpeg_allowed_formats = ActiveStorage.ffmpeg_allowed_formats
|
|
34
35
|
|
|
35
36
|
config.active_storage.variable_content_types = %w(
|
|
36
37
|
image/png
|
|
@@ -93,6 +94,13 @@ module ActiveStorage
|
|
|
93
94
|
ActiveStorage.variant_processor = app.config.active_storage.variant_processor || :mini_magick
|
|
94
95
|
ActiveStorage.previewers = app.config.active_storage.previewers || []
|
|
95
96
|
ActiveStorage.analyzers = app.config.active_storage.analyzers || []
|
|
97
|
+
|
|
98
|
+
if ActiveStorage::MINIMAGICK_AVAILABLE && !ActiveStorage::MINIMAGICK_UNSECURABLE
|
|
99
|
+
ActiveStorage::ImageMagick.apply_policy
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
ActiveStorage.require_securable_mini_magick! if ActiveStorage.variant_processor == :mini_magick
|
|
103
|
+
|
|
96
104
|
ActiveStorage.paths = app.config.active_storage.paths || {}
|
|
97
105
|
ActiveStorage.routes_prefix = app.config.active_storage.routes_prefix || "/rails/active_storage"
|
|
98
106
|
ActiveStorage.draw_routes = app.config.active_storage.draw_routes != false
|
|
@@ -121,6 +129,7 @@ module ActiveStorage
|
|
|
121
129
|
ActiveStorage.content_types_allowed_inline = app.config.active_storage.content_types_allowed_inline || []
|
|
122
130
|
ActiveStorage.binary_content_type = app.config.active_storage.binary_content_type || "application/octet-stream"
|
|
123
131
|
ActiveStorage.video_preview_arguments = app.config.active_storage.video_preview_arguments || "-y -vframes 1 -f image2"
|
|
132
|
+
ActiveStorage.ffmpeg_allowed_formats = app.config.active_storage.ffmpeg_allowed_formats
|
|
124
133
|
ActiveStorage.track_variants = app.config.active_storage.track_variants || false
|
|
125
134
|
ActiveStorage.streaming_chunk_max_size = app.config.active_storage.streaming_chunk_max_size || 100.megabytes
|
|
126
135
|
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
|
|
@@ -15,6 +15,13 @@ module ActiveStorage
|
|
|
15
15
|
attr_reader :client, :container, :signer
|
|
16
16
|
|
|
17
17
|
def initialize(storage_account_name:, storage_access_key:, container:, public: false, **options)
|
|
18
|
+
ActiveStorage.deprecator.warn <<~MSG.squish
|
|
19
|
+
`ActiveStorage::Service::AzureStorageService` is deprecated and will be
|
|
20
|
+
removed in Rails 8.1.
|
|
21
|
+
Please try the `azure-blob` gem instead.
|
|
22
|
+
This gem is not maintained by the Rails team, so please test your applications before deploying to production.
|
|
23
|
+
MSG
|
|
24
|
+
|
|
18
25
|
@client = Azure::Storage::Blob::BlobService.create(storage_account_name: storage_account_name, storage_access_key: storage_access_key, **options)
|
|
19
26
|
@signer = Azure::Storage::Common::Core::Auth::SharedAccessSignature.new(storage_account_name, storage_access_key)
|
|
20
27
|
@container = container
|
|
@@ -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
|
|
@@ -228,5 +217,9 @@ module ActiveStorage
|
|
|
228
217
|
def custom_metadata_headers(metadata)
|
|
229
218
|
metadata.transform_keys { |key| "x-goog-meta-#{key}" }
|
|
230
219
|
end
|
|
220
|
+
|
|
221
|
+
def content_length_range(content_length)
|
|
222
|
+
"#{content_length},#{content_length}"
|
|
223
|
+
end
|
|
231
224
|
end
|
|
232
225
|
end
|
|
@@ -30,6 +30,13 @@ module ActiveStorage
|
|
|
30
30
|
|
|
31
31
|
def initialize(primary:, mirrors:)
|
|
32
32
|
@primary, @mirrors = primary, mirrors
|
|
33
|
+
@executor = Concurrent::ThreadPoolExecutor.new(
|
|
34
|
+
min_threads: 1,
|
|
35
|
+
max_threads: mirrors.size,
|
|
36
|
+
max_queue: 0,
|
|
37
|
+
fallback_policy: :caller_runs,
|
|
38
|
+
idle_time: 60
|
|
39
|
+
)
|
|
33
40
|
end
|
|
34
41
|
|
|
35
42
|
# Upload the +io+ to the +key+ specified to all services. The upload to the primary service is done synchronously
|
|
@@ -75,10 +82,12 @@ module ActiveStorage
|
|
|
75
82
|
end
|
|
76
83
|
|
|
77
84
|
def perform_across_services(method, *args)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
tasks = each_service.collect do |service|
|
|
86
|
+
Concurrent::Promise.execute(executor: @executor) do
|
|
87
|
+
service.public_send method, *args
|
|
88
|
+
end
|
|
81
89
|
end
|
|
90
|
+
tasks.each(&:value!)
|
|
82
91
|
end
|
|
83
92
|
end
|
|
84
93
|
end
|
data/lib/active_storage.rb
CHANGED
|
@@ -376,6 +376,12 @@ module ActiveStorage
|
|
|
376
376
|
|
|
377
377
|
mattr_accessor :video_preview_arguments, default: "-y -vframes 1 -f image2"
|
|
378
378
|
|
|
379
|
+
mattr_accessor :ffmpeg_allowed_formats, default: %w[ mov matroska avi mpeg mpegts flv asf ogg mp3 wav flac aac aiff caf ].freeze
|
|
380
|
+
|
|
381
|
+
def self.ffmpeg_format_whitelist_arguments # :nodoc:
|
|
382
|
+
[ "-format_whitelist", Array(ffmpeg_allowed_formats).join(",") ] unless ffmpeg_allowed_formats.nil?
|
|
383
|
+
end
|
|
384
|
+
|
|
379
385
|
module Transformers
|
|
380
386
|
extend ActiveSupport::Autoload
|
|
381
387
|
|
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:
|
|
4
|
+
version: 8.0.5.2
|
|
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:
|
|
18
|
+
version: 8.0.5.2
|
|
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:
|
|
25
|
+
version: 8.0.5.2
|
|
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:
|
|
32
|
+
version: 8.0.5.2
|
|
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:
|
|
39
|
+
version: 8.0.5.2
|
|
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:
|
|
46
|
+
version: 8.0.5.2
|
|
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:
|
|
53
|
+
version: 8.0.5.2
|
|
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:
|
|
60
|
+
version: 8.0.5.2
|
|
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:
|
|
67
|
+
version: 8.0.5.2
|
|
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
|
|
@@ -190,10 +192,10 @@ licenses:
|
|
|
190
192
|
- MIT
|
|
191
193
|
metadata:
|
|
192
194
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
|
193
|
-
changelog_uri: https://github.com/rails/rails/blob/
|
|
194
|
-
documentation_uri: https://api.rubyonrails.org/
|
|
195
|
+
changelog_uri: https://github.com/rails/rails/blob/v8.0.5.2/activestorage/CHANGELOG.md
|
|
196
|
+
documentation_uri: https://api.rubyonrails.org/v8.0.5.2/
|
|
195
197
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
|
196
|
-
source_code_uri: https://github.com/rails/rails/tree/
|
|
198
|
+
source_code_uri: https://github.com/rails/rails/tree/v8.0.5.2/activestorage
|
|
197
199
|
rubygems_mfa_required: 'true'
|
|
198
200
|
rdoc_options: []
|
|
199
201
|
require_paths:
|
|
@@ -202,7 +204,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
202
204
|
requirements:
|
|
203
205
|
- - ">="
|
|
204
206
|
- !ruby/object:Gem::Version
|
|
205
|
-
version: 3.
|
|
207
|
+
version: 3.2.0
|
|
206
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
209
|
requirements:
|
|
208
210
|
- - ">="
|