Images uploaded with wrong extension trigger ActiveStorage::IntegrityError
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
調査の方向性
ActiveStorage::Service::CloudinaryService#ext_for_fileから始め、報告されている monkey patch と拡張子の選択を比較します。.png拡張子の名前が付いたJPEGを使ってRails Direct Uploadを再現し、その後、Cloudinary URL、blob checksum、ActiveStorage::IntegrityErrorに至る経路を追跡します。元のアップロード画像を、checksumの不一致や意図しない形式変換なしにダウンロードして解析できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Ruby
- スター
- 420
- フォーク
- 282
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cloudinary/cloudinary_gem のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 52/100
cloudinary/cloudinary_gem#591 · コメント 3 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
cloudinary/cloudinary_gem#582 · コメント 1 件 ·
-
404's when fetching .eml files (from Action Mailbox)再び着手できるかも @rnamba-cloudinary が 400 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
cloudinary/cloudinary_gem#581 · コメント 1 件 ·
-
BlobKey, MirrorService and Sidekiq 8 are incompatible再び着手できるかも @const-cloudinary が 541 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
cloudinary/cloudinary_gem#573 · コメント 3 件 · 担当者 1 名 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
cloudinary/cloudinary_gem#562 · コメント 9 件 ·
cloudinary/cloudinary_gem の issue をすべて見る
似ている issue
-
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
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
flisk-sh/flisk-labs#22 ·
-
1.severity: security
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
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
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
Huerte/algo-solutions-python#260 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
internal
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Kong/developer.konghq.com#8080 ·
メンテナーはふだん 1 日以内に返信