-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Issues with Spoof File Checks #1429
Comments
No, the spoof detector is not affected by that helper, only the enforced check for content type/filename validations. What is the filename and type of file that you're uploading? What is the output of |
The filename is "ios_push_notification_certificate.pem" and the type that set on the form uploader is "application/x-x509-ca-cert". When I run |
Well, that's annoying. The file command completely fails us here. I think letting |
No problem. I thought I could get around it by registering a new mime-type for the lookup but wasn't able to have that work either. Thanks for the quickly reply and looking into this. Thought I was going nuts. |
I've got the same problem here. I'm wondering if there's a workaround for the time being until there's an update. For now, I'll just roll back to the previous version. Overall though, this looks like a nice release. Looking forward to testing it out more. Thanks for producing this gem. |
This also messes with files assigned with uri-open for me (same error) |
Workaround: require 'paperclip/media_type_spoof_detector'
module Paperclip
class MediaTypeSpoofDetector
def spoofed?
false
end
end
end |
@glebtv is right. |
Nope, it doesn't. But that sounds like something we can fix. I assume the URL will have an extension, so we can tack one on to the Tempfile name. |
I have come across the same problem attempting to upload a word .doc file which is resulting in the spoofed error message as the file utility returns null for the mime-type. This is on an Ubuntu 12.04.4 LTS (GNU/Linux 3.8.0-29-generic x86_64) server with version is 5.09 of the file utility and its magic.mgc file from 2011. These are the relevant rails application log entries:
For reference, I can upload the same file in development on my mac running mavericks with version is 5.04 of the file utility. |
I also have issue with LinkedIn avatars (probably other networks have the same)
and model is not saved |
The issue also affects Facebook avatars captured from OAuth authentication. The image comes back as part of the JSON response as an URL of the form http://graph.facebook.com/10000000/picture?type=large (note no extension), which then fails validation. |
@chrismhilton - can you send me an example of a file that gives a null mime-type? I cannot replicate the condition where |
Here's an attachment that was previously saved from gravatar. It originally had no extension. When I reprocess it, it fails spoof detection: (note: the trailing dot is part of the url)
|
Also hits when there's a difference between production / dev dbs... I have an image attachment for companies which uses different s3 buckets for production vs dev. When I copy the production db to dev, paperclip tries to download the image from the production s3 bucket and doesn't have access. So it fails with the same error message. Frustrating. |
An additional note: on CentOS 5.10 (at least) it seems the file command doesn't have a --mime-type parameter, just --mime, which causes spoof detection to fail.
|
I can confirm (after @chrismhilton) that It is also a nuisance that the anti-spoof validation runs on every save, as it means an unchanged file has to be pulled down from S3. Could it be applied only when the file has changed? Happy to submit a pr. |
There is a change on master (8b5289b) that only checks for spoofing when the file changes. That should go out relatively soon. @browntiger Could you open another ticket about that, so we can keep separate causes for the same problem contained? Thanks. |
I confirm spoofed problems with facebook image URI |
Where's the documentation to re-enable setting and changing attachments to an object? I'm having issues as well with the latest version of Paperclip as far as normal pngs being seen as invalid png files on Windows. However, it seems more controlled and has to do more of not being able to remove the restriction of assigning an attachment to an object via the command line (for testing purposes, as well as for mocking,stubbing, and extending factories). |
im getting an error: "Validation failed: Datafile has an extension that does not match its contents" when saving an xml file through a rake task fetching from FTP server. the same file can be attached to the model through active admin. running file sc.xml --mime-type gives application/xml. Is this the same issue? im using ruby 2.0.0 and rails 4.0.2 . |
@glebtv 's workaround got me rolling for now. (thanks!) and probably confirms its the same issue i guess. |
Sorry for the noobish question, but where do I put this workaround? In my model that has the paperclip attachment? As a helper somewhere? |
@ays0110 i put it at the top of the rake file that was having problems. that might not be best practice, but there it is. worked for me. might help you. i'd try it a few places and see if it works. then think about where is best for it. for me its a bit hacky, so as near to the need as possible. hth |
@asecondwill /config/initializers/paperclip.rb is the natural place for it. |
@rossshannon ah ok, yeah that makes sense. thank you. |
The content not match.. :( |
@lozandier - Your problem is probably that you don't have the |
I still have this 'Content Type Spoof' error with the lastest paperclip patch! |
@kenn's tip above works for me! |
I get it working now. I did exactly the opposite of @kenn's tip. It's like this:
|
@dkonayuki that worked for me as well for omniauth with paperclip 4.1.1
note: adding :image_size => 'SIZE' as an option for omniauth breaks both methods :/ |
@chrismhilton I'm on ubuntu 12.04 LTS as well. You need to set the path to the |
@chrismhilton actually, you should use |
Hi When I upload files (word, excel) with Japanese content in it I tried adding 'do_not_validate_attachment_file_type' but no use. I do not want to override the paperclip module Please help me to fix. |
If you are using ruby on windows (like me, sadly) then note that there is no "file" command on windows for paperclip to check spoofing. As such, you always get a message like this in your rails server: [paperclip] Content Type Spoof: Filename upload_test.csv (["text/csv", "text/comma-separated-values"]), content type discovered from file command: . See documentation to allow this combination. Thankfully, you can add the file command using the correct Gnuwin32 open source package. Make sure you set your environment variables "path" to include the installed bin directory and close all windows terminals to pick up the change (this includes any IDE's, such as RubyMine) then restart your rails server. |
Getting the same issue with |
Is there a workaround to allow you to use something like:
... and specify image_size? |
@ozvillafan I recommend using Ubuntu or another well-received version of On Tue, Sep 2, 2014 at 3:49 AM, ozvillafan [email protected] wrote:
Kevin Lozandier |
@mehulkar were you able to pass the spoof detection? I'm getting errors when uploading images via api as base64 string and then decoding and saving to paperclip. File is |
@scanales we basically did a mass override and turned off the feature using @glebtv's workaround since we can trust our users: require 'paperclip/media_type_spoof_detector'
module Paperclip
class MediaTypeSpoofDetector
def spoofed?
false
end
end
end |
Same error, using latest paperclip gem relese, on Ubuntu 14.04. Confirming that workaround from @glebtv does work. |
@mehulkar I've tried that but it's not working for me, I'm on CentOS. I get the following error:
This is the code I added to the initializer:
|
require 'paperclip/media_type_spoof_detector' module Paperclip
class MediaTypeSpoofDetector
def type_from_file_command
begin
Paperclip.run("file", "-b --mime :file", :file => @file.path)
rescue
end
end
end
end seems to work when file is uploaded on windows |
As an improvement to @glebtv's workaround you might want to try this: # config/initializers/paperclip.rb
require 'paperclip/media_type_spoof_detector'
module Paperclip
class MediaTypeSpoofDetector
old_spoofed = instance_method(:spoofed?)
define_method(:spoofed?) do
if supplied_file_content_types.count > 0
old_spoofed.bind(self).()
else
false
end
end
end
end |
On the staging host, Paperclip repeatedly reports non-spoofed attachments as spoofed, which breaks ingestion. We're quick-fixing it with a monkey patch for now, and in doing so will incur some technical debt. We'll circle back later and attempt to come up with a more robust fix, perhaps by avioding paperclip alltogether. See thoughtbot/paperclip#1429 for more on this issue.
Hopefully this replaces the monkey patching: #2378 |
No need for monkey patch. Paperclip has content-type checking and media-type checking. Both seem to do the same thing using Media-type checking uses the global config of You can do the following to control media-type and content-type checking:
|
Using the latest version of Paperclip (5.1.0) resolved the issue for me. I'm suspecting
did the trick for me. Source: https://github.com/thoughtbot/paperclip/blob/master/NEWS for 5.1.0 |
Standard Alpine Linux (in docker) does not come with the 'file' command so you may want to verify you have it to start with.
|
I got the same problem on Alpine (Docker), the problem solved by adding this on my Dockerfile: Thanks! |
This is the perfect solution!!! |
Hi,
I just upgraded to Paperclip 4.0 and now I'm getting an error about spoofed_media_type. I found the helper for:
But I still receive error the error message. Does Paperclip::MediaTypeSpoofDetector.using(adapter, value.original_filename).spoofed? not take into account the do_not_validate?
The text was updated successfully, but these errors were encountered: