Class: Paperclip::MediaTypeSpoofDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/paperclip/media_type_spoof_detector.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, name, content_type) ⇒ MediaTypeSpoofDetector

Returns a new instance of MediaTypeSpoofDetector.



7
8
9
10
11
# File 'lib/paperclip/media_type_spoof_detector.rb', line 7

def initialize(file, name, content_type)
  @file = file
  @name = name
  @content_type = content_type || ""
end

Class Method Details

.using(file, name, content_type) ⇒ Object



3
4
5
# File 'lib/paperclip/media_type_spoof_detector.rb', line 3

def self.using(file, name, content_type)
  new(file, name, content_type)
end

Instance Method Details

#spoofed?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
# File 'lib/paperclip/media_type_spoof_detector.rb', line 13

def spoofed?
  if has_name? && has_extension? && media_type_mismatch? && mapping_override_mismatch?
    Paperclip.log("Content Type Spoof: Filename #{File.basename(@name)} (#{supplied_content_type} from Headers, #{content_types_from_name.map(&:to_s)} from Extension), content type discovered from file command: #{calculated_content_type}. See documentation to allow this combination.")
    true
  else
    false
  end
end