Images uploaded with wrong extension trigger ActiveStorage::IntegrityError
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 55/100
Línea de trabajo
Comienza con ActiveStorage::Service::CloudinaryService#ext_for_file y compara su selección de extensión con el monkey patch reportado. Reproduce un Rails Direct Upload usando un JPEG cuyo nombre termina en .png y, a continuación, sigue la URL de Cloudinary, el checksum del blob y la ruta de ActiveStorage::IntegrityError. Se considera terminado cuando la imagen subida originalmente se puede descargar y analizar sin una discrepancia de checksum ni una transformación de formato no intencionada.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Ruby
- Estrellas
- 420
- Forks
- 282
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de cloudinary/cloudinary_gem
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 52/100
cloudinary/cloudinary_gem#591 · 3 comentarios ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
cloudinary/cloudinary_gem#582 · 1 comentario ·
-
404's when fetching .eml files (from Action Mailbox)Quizá libre de nuevo @rnamba-cloudinary la tomó hace 400 días y no hay ningún pull request abierto. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
cloudinary/cloudinary_gem#581 · 1 comentario ·
-
BlobKey, MirrorService and Sidekiq 8 are incompatibleQuizá libre de nuevo @const-cloudinary la tomó hace 541 días y no hay ningún pull request abierto. Abierto
cloudinary/cloudinary_gem#573 · 3 comentarios · 1 asignado ·
-
ActiveStorage Mirror IssueAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
cloudinary/cloudinary_gem#562 · 9 comentarios ·
Todos los issues de cloudinary/cloudinary_gem
Issues similares
-
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
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
flisk-sh/flisk-labs#22 ·
-
1.severity: security
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
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
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
Huerte/algo-solutions-python#260 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
internal
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Kong/developer.konghq.com#8080 ·
Los mantenedores suelen responder en 1 día