Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primarly rely on magic to determine mime type #2570

Closed
MarcelEeken opened this issue May 21, 2021 · 3 comments
Closed

Primarly rely on magic to determine mime type #2570

MarcelEeken opened this issue May 21, 2021 · 3 comments

Comments

@MarcelEeken
Copy link

MarcelEeken commented May 21, 2021

I have been investigating some issue lately about file uploads and mimetype determination and was looking at how CarrierWave implements it, and also how other projects implement it.

I saw in the source code of CarrierWave that it primarly relies on the given content_type of the file being attached

def content_type
@content_type ||=
existing_content_type ||
marcel_magic_content_type ||
mini_mime_content_type
end
.

As most files used by CarrierWave are potentially uploaded this can be an entry point for abuse, as the given content_type can be easily spoofed, as also has been mentioned here #1942 (comment).

With the recognition here #2465 (comment) as well that spoofing protection will become more important is it maybe an idea to not rely on the existing content type, and fully rely on the content type given by tools such as Marcel?

This is by the way how it is now solved in ActiveStorage https://github.com/rails/rails/blob/e848e8861d5c9221b77e039c2f041abced3aa577/activestorage/app/models/active_storage/blob/identifiable.rb#L21-L23

@aquintino
Copy link

Is there any official patch/solution to this issue? I am thinking of patching sanitized file to ignore the existing content type if file is an instance of ActionDispatch::Http::UploadedFile

@varentsov
Copy link

any updates on that issue?

@mshibuya mshibuya added this to the Release v3.0.0 milestone Jan 14, 2023
@mshibuya
Copy link
Member

Quite agree, changed in a2ca59c 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants