Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.

Commit 18a427d

Browse files
committed
Merge pull request #2126 from bdewater/v4.3
Backport fix for excessive logging from media type spoof detector
2 parents 4e047f2 + ebeccb1 commit 18a427d

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Bug Fix: megabytes of mime-types info in logs when a spoofed media type is detected.
2+
13
4.3.5 (2/8/2016):
24
* Bug Fix: Remove deprecation warnings for v5.0 for now. Will re-add once the version has landed.
35

lib/paperclip/media_type_spoof_detector.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def initialize(file, name, content_type)
1212

1313
def spoofed?
1414
if has_name? && has_extension? && media_type_mismatch? && mapping_override_mismatch?
15-
Paperclip.log("Content Type Spoof: Filename #{File.basename(@name)} (#{supplied_content_type} from Headers, #{content_types_from_name} from Extension), content type discovered from file command: #{calculated_content_type}. See documentation to allow this combination.")
15+
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.")
1616
true
1717
else
1818
false

spec/paperclip/media_type_spoof_detector_spec.rb

+12-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,18 @@
4444
end
4545
end
4646

47-
it "rejects a file if named .html and is as HTML, but we're told JPG" do
48-
file = File.open(fixture_file("empty.html"))
49-
assert Paperclip::MediaTypeSpoofDetector.using(file, "empty.html", "image/jpg").spoofed?
47+
context "file named .html and is as HTML, but we're told JPG" do
48+
let(:file) { File.open(fixture_file("empty.html")) }
49+
let(:spoofed?) { Paperclip::MediaTypeSpoofDetector.using(file, "empty.html", "image/jpg").spoofed? }
50+
51+
it "rejects the file" do
52+
assert spoofed?
53+
end
54+
55+
it "logs info about the detected spoof" do
56+
Paperclip.expects(:log).with('Content Type Spoof: Filename empty.html (image/jpg from Headers, ["text/html"] from Extension), content type discovered from file command: text/html. See documentation to allow this combination.')
57+
spoofed?
58+
end
5059
end
5160

5261
it "does not reject if content_type is empty but otherwise checks out" do

0 commit comments

Comments
 (0)