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

Backport fix for excessive logging from media type spoof detector #2126

Merged
merged 2 commits into from Mar 11, 2016
Merged

Backport fix for excessive logging from media type spoof detector #2126

merged 2 commits into from Mar 11, 2016

Conversation

bdewater
Copy link
Contributor

@bdewater bdewater commented Mar 9, 2016

Backport 8339e0f (#2017) to 4.3 to prevent excessive logging, which might be abused. Fixes #2125.

Please release 4.3.6 as soon as possible to prevent abuse.

Before the error message was sometimes millions of characters long.

> [paperclip] Content Type Spoof: Filename a.csv
> (application/octet-stream from Headers,
> [#<MIME::Type::Columnar:0x007f9f90f89fa8
> @container=#<MIME::Types:0x007f9f90b09d98 ... snip millions of
> characters of output here ...>], @content_type="text/csv",
> @raw_media_type="text", @raw_sub_type="csv", @simplified="text/csv",
> @i18n_key="text.csv", @media_type="text", @sub_type="csv",
> @extensions=["csv"]>] from Extension), content type discovered from
> file command: application/zip. See documentation to allow this
> combination.

Now becomes:

> [paperclip] Content Type Spoof: Filename a.csv
> (application/octet-stream from Headers,
> ["text/comma-separated-values", "text/csv"] from Extension), content
> type discovered from file command: application/zip. See documentation
> to allow this combination.

[fixes #2017]
@@ -12,7 +12,7 @@ def initialize(file, name, content_type)

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} from Extension), content type discovered from file command: #{calculated_content_type}. See documentation to allow this combination.")
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.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [289/80]

@tute
Copy link
Contributor

tute commented Mar 11, 2016

Thank you! Would you like to squash the commits together? Also, I think the context in the PR description is very relevant, can you add it to the commit messages please? Then I'll merge. Thank you!

…our to prevent regressions.

Excessive logging can fill up disk space and become a denial of service attack, see https://cwe.mitre.org/data/definitions/779.html
@bdewater
Copy link
Contributor Author

Squashed and added info. How does it look @tute ?

tute added a commit that referenced this pull request Mar 11, 2016
Backport fix for excessive logging from media type spoof detector
@tute tute merged commit 18a427d into thoughtbot:v4.3 Mar 11, 2016
@tute
Copy link
Contributor

tute commented Mar 11, 2016

Thank you!

@bdewater bdewater deleted the v4.3 branch March 12, 2016 08:07
@bdewater
Copy link
Contributor Author

Great! Is a new version on the way? :)

I can do a separate PR to bring the test to the master branch if you'd like.

@tute
Copy link
Contributor

tute commented Mar 12, 2016

Great! Is a new version on the way? :)

Yep, soon!

I can do a separate PR to bring the test to the master branch if you'd like.

Please do. Thank you!

berkes added a commit to berkes/spree that referenced this pull request Apr 18, 2016
"It's possible to cause a DoS by uploading files with a spoofed media
type, because it causes megabytes of logging to be written."

See thoughtbot/paperclip#2017 and
thoughtbot/paperclip#2126
berkes added a commit to berkes/spree that referenced this pull request Apr 18, 2016
"It's possible to cause a DoS by uploading files with a spoofed media
type, because it causes megabytes of logging to be written."

See thoughtbot/paperclip#2017 and
thoughtbot/paperclip#2126
berkes added a commit to berkes/spree that referenced this pull request Apr 18, 2016
"It's possible to cause a DoS by uploading files with a spoofed media
type, because it causes megabytes of logging to be written."

See thoughtbot/paperclip#2017 and
thoughtbot/paperclip#2126
damianlegawiec pushed a commit to spree/spree that referenced this pull request Apr 18, 2016
"It's possible to cause a DoS by uploading files with a spoofed media
type, because it causes megabytes of logging to be written."

See thoughtbot/paperclip#2017 and
thoughtbot/paperclip#2126
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants