dragonfly icon indicating copy to clipboard operation
dragonfly copied to clipboard

Lack of magic byte file type detection / ImageTragick mitigation

Open bdewater opened this issue 8 years ago • 3 comments

I'm currently evaluating different file upload solutions for Rails and as far as I can tell Dragonfly solely relies on the file extension to identify the content type of files. Given the recent ImageTragick vulnerability (CVE-2016–3714) we're reminded that blindly trusting user input/files and passing it along for processing is a bad thing. Benign use cases like #386 and #434 would also benefit from from getting the correct mime type by inspecting magic bytes before doing anything with it.

The code has an example for #shell_eval of using the file command, but it is only used for the also vulnerable identify command in the ImageMagick plugin.

Some references on how other libraries dealt with similar issues:

bdewater avatar Jun 01 '16 09:06 bdewater

hi there - thanks for the heads up - yes, this is something that needs looking into. it actually used to use the file command automatically but that incurred other problems (maybe because of the way it was implemented). I'll try to come back to this in the next week or so (I'm incredibly busy over the next few days)

markevans avatar Jun 01 '16 12:06 markevans

Hi Mark, thanks for your reply and your work on this gem. I've dug in the history and it was removed in 4b0a43e2dd8b5733529aff53b8f0c948cb867e3a although the commit message doesn't mention any problems it would have caused.

Those other two gems use the #by_magic method from https://github.com/minad/mimemagic which is probably less prone to edge cases than calling shell commands. Paperclip uses file as a fallback.

bdewater avatar Jun 01 '16 15:06 bdewater

In our project we patched this vulnerability by tweaking ImageMagick directly... do you think that doesn't suffice, or it's just a paranoid check to avoid generating more vectors of attack?

nicops avatar Jun 03 '16 15:06 nicops