Images uploaded with wrong extension trigger ActiveStorage::IntegrityError
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Bắt đầu với ActiveStorage::Service::CloudinaryService#ext_for_file và so sánh việc chọn phần mở rộng của nó với monkey patch đã được báo cáo. Tái hiện một Rails Direct Upload bằng JPEG có tên với phần mở rộng .png, sau đó lần theo URL Cloudinary, checksum của blob và đường dẫn ActiveStorage::IntegrityError. Hoàn thành khi ảnh được tải lên ban đầu có thể được tải xuống và phân tích mà không xảy ra sai lệch checksum hoặc chuyển đổi định dạng ngoài ý muốn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug in a sentence or two.
When using Rails Direct Uploads, we can't analyze a file before it reaches Cloudinary. If a user uploads an image with the wrong extension (say a JPEG named image.png), then Cloudinary will return an URL ending with .png, which requests a transformation of the image to PNG, resulting in a checksum that does not match the one stored in the associated ActiveStorage::Blob, which triggers ActiveStorage::IntegrityError.
Issue Type (Can be multiple)
- Build - Cannot install or import the SDK
- Performance - Performance issues
- Behaviour - Functions are not working as expected (such as generate URL)
- Documentation - Inconsistency between the docs and behaviour
- Other (Specify)
Operating System
- Linux
- Windows
- macOS
- All
Environment and Libraries (fill in the version numbers)
- Cloudinary Ruby SDK version - 2.4.4
- Ruby Version - 3.4.10
- Rails Version - 8.1.3
Current workaround
In our codebase, we monkey patched ActiveStorage::Service::CloudinaryService#ext_for_file like this as a workaround:
# The original ext_for_file method takes the extension from the filename and only falls back to the
# content type when the filename carries none. What this patch does is let Rails determine the real
# content type of the file, and if it matches the filename extension return this extension, otherwise
# return an extension that really matches the content_type.
#
# This logic does not apply to "raw" resource types, as these are never transcoded by cloudinary.
def ext_for_file(key, filename = nil, content_type = nil)
attributes = key.is_a?(ActiveStorage::BlobKey) ? key.attributes : {}
content_type = content_type.presence || attributes[:content_type]
return super if content_type_to_resource_type(content_type).eql?('raw')
# { 'identified' => true } in metadata means Rails has analyzed the file and determined its true
# content type. It does that by downloading the file from the provided url, at the moment of
# attaching the blob to the record. Before that, the content type is what the client said it was,
# which can be wrong. Returning nil before identification forces no extension and therefore no
# conversion on the Cloudinary side. That allows Rails to download and analyze the original file
# intead of a converted one.
return nil unless attributes.dig(:metadata, 'identified')
filename = ActiveStorage::Filename.wrap(filename.presence || attributes[:filename])
filename_extension = filename.extension_without_delimiter
content_type_extensions = Marcel::TYPE_EXTS[content_type]
return filename_extension if content_type_extensions.blank?
content_type_extensions.find { it == filename_extension } || content_type_extensions.first
end
- Ngôn ngữ chính
- Ruby
- Star
- 420
- Fork
- 282
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của cloudinary/cloudinary_gem
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 52/100
cloudinary/cloudinary_gem#591 · 3 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
cloudinary/cloudinary_gem#582 · 1 bình luận ·
-
404's when fetching .eml files (from Action Mailbox)Có thể làm lại được @rnamba-cloudinary đã nhận 400 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
cloudinary/cloudinary_gem#581 · 1 bình luận ·
-
BlobKey, MirrorService and Sidekiq 8 are incompatibleCó thể làm lại được @const-cloudinary đã nhận 541 ngày trước và không có pull request nào đang mở. Đang mở
cloudinary/cloudinary_gem#573 · 3 bình luận · 1 người được giao ·
-
ActiveStorage Mirror IssueĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
cloudinary/cloudinary_gem#562 · 9 bình luận ·
Tất cả issue của cloudinary/cloudinary_gem
Issue tương tự
-
area: ci benchmark build developer-experience difficulty: easy dx enhancement github-actions good first issue hacktoberfest help wanted performance quality rank: 8 kyu ruby tech: ruby
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
flisk-sh/flisk-labs#22 ·
-
1.severity: security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
15-minutes 5-minutes algorithm any-language beginner-friendly c cpp csharp easy go good first issue hacktoberfest help wanted java javascript kotlin python rust swift typescript
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
Huerte/algo-solutions-python#260 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
internal
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Kong/developer.konghq.com#8080 ·
Maintainer thường phản hồi trong vòng 1 ngày