carrierwave 0.11.0 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of carrierwave might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 815b971ebb21afd416f1de7f2d5d35a67c7231bf
4
- data.tar.gz: 59b36c18c02eefb0f81438b54200c5f857759589
3
+ metadata.gz: 8c1689fd908e56b671c45e5cb1eebe3ec938a4df
4
+ data.tar.gz: 89668d77484c786139f513dc1b82c82879da4e11
5
5
  SHA512:
6
- metadata.gz: 40f40f2cdd4e0657843260e6830e39e87465fd3b9e881e2dc3f1298479272cb0accbf7a9d4262f1c8df5d7573de4e7c49776b484ec7ad84fa7ad01462455676f
7
- data.tar.gz: b967fe877468cb9c26bc7fdc7c861f37692ceaf2293457c3e4fe7f9faf773abda94243dceef9ef38c4fdad979853ecac47b22df0b36ae945af0dfb830bbdeed9
6
+ metadata.gz: a03780cb6e64ad439c1f12378be2f4392617dbbe9f83329eccc6bc05064385e0e95a4b4609e32d922a0ce6d5543bbc795eb4abb8e429d5e366040fdfa3c82bfd
7
+ data.tar.gz: ee26ab882ed995b677c38e6064843101633a07166cf2dda0e522bf1b13eb7a30a373312d67b786bc86365fd3ef4cb974f8f57a564dafbf9eafaf1c60b7e3e3e8
data/README.md CHANGED
@@ -161,6 +161,22 @@ class MyUploader < CarrierWave::Uploader::Base
161
161
  end
162
162
  ```
163
163
 
164
+ ### CVE-2016-3714 (ImageTragick)
165
+ This version of CarrierWave has the ability to mitigate CVE-2016-3714. However, you **MUST** set a `content_type_whitelist` in your uploaders for this protection to be effective, and you **MUST** either disable ImageMagick's default SVG delegate or use the RSVG delegate for SVG processing.
166
+
167
+ A valid whitelist that will restrict your uploader to images only, and mitigate the CVE is:
168
+
169
+ ```ruby
170
+ class MyUploader < CarrierWave::Uploader::Base
171
+ def content_type_whitelist
172
+ [/image\//]
173
+ end
174
+ end
175
+ ```
176
+
177
+ **WARNING**: A `content_type_whitelist` is the only form of whitelist or blacklist supported by CarrierWave that can effectively mitigate against CVE-2016-3714. Use of `extension_type_whitelist` will not inspect the file headers, and thus still leaves your application open to the vulnerability.
178
+
179
+
164
180
  ### Filenames and unicode chars
165
181
 
166
182
  Another security issue you should care for is the file names (see
@@ -3,6 +3,7 @@
3
3
  require 'pathname'
4
4
  require 'active_support/core_ext/string/multibyte'
5
5
  require 'mime/types'
6
+ require 'mimemagic'
6
7
 
7
8
  module CarrierWave
8
9
 
@@ -244,12 +245,10 @@ module CarrierWave
244
245
  # [String] the content type of the file
245
246
  #
246
247
  def content_type
247
- return @content_type if @content_type
248
- if @file.respond_to?(:content_type) and @file.content_type
249
- @content_type = @file.content_type.to_s.chomp
250
- elsif path
251
- @content_type = ::MIME::Types.type_for(path).first.to_s
252
- end
248
+ @content_type ||=
249
+ existing_content_type ||
250
+ mime_magic_content_type ||
251
+ mime_types_content_type
253
252
  end
254
253
 
255
254
  ##
@@ -309,6 +308,22 @@ module CarrierWave
309
308
  return name.mb_chars.to_s
310
309
  end
311
310
 
311
+ def existing_content_type
312
+ if @file.respond_to?(:content_type) && @file.content_type
313
+ @file.content_type.to_s.chomp
314
+ end
315
+ end
316
+
317
+ def mime_magic_content_type
318
+ MimeMagic.by_magic(File.open(path)).try(:type) if path
319
+ rescue Errno::ENOENT
320
+ nil
321
+ end
322
+
323
+ def mime_types_content_type
324
+ ::MIME::Types.type_for(path).first.to_s if path
325
+ end
326
+
312
327
  def split_extension(filename)
313
328
  # regular expressions to try for identifying extensions
314
329
  extension_matchers = [
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "fog"
4
-
5
3
  module CarrierWave
6
4
  module Storage
7
5
 
@@ -1,9 +1,11 @@
1
1
  require "carrierwave/storage/abstract"
2
2
  require "carrierwave/storage/file"
3
3
 
4
- begin
5
- require "fog"
6
- rescue LoadError
4
+ %w(aws google openstack rackspace).each do |fog_dependency|
5
+ begin
6
+ require "fog/#{fog_dependency}"
7
+ rescue LoadError
8
+ end
7
9
  end
8
10
 
9
11
  require "carrierwave/storage/fog" if defined?(Fog)
@@ -0,0 +1,48 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module ContentTypeBlacklist
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before :cache, :check_content_type_blacklist!
8
+ end
9
+
10
+ ##
11
+ # Override this method in your uploader to provide a blacklist of files content types
12
+ # which are not allowed to be uploaded.
13
+ # Not only strings but Regexp are allowed as well.
14
+ #
15
+ # === Returns
16
+ #
17
+ # [NilClass, String, Regexp, Array[String, Regexp]] a blacklist of content types which are not allowed to be uploaded
18
+ #
19
+ # === Examples
20
+ #
21
+ # def content_type_blacklist
22
+ # %w(text/json application/json)
23
+ # end
24
+ #
25
+ # Basically the same, but using a Regexp:
26
+ #
27
+ # def content_type_blacklist
28
+ # [/(text|application)\/json/]
29
+ # end
30
+ #
31
+ def content_type_blacklist; end
32
+
33
+ private
34
+
35
+ def check_content_type_blacklist!(new_file)
36
+ content_type = new_file.content_type
37
+ if content_type_blacklist && blacklisted_content_type?(content_type)
38
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_blacklist_error", content_type: content_type)
39
+ end
40
+ end
41
+
42
+ def blacklisted_content_type?(content_type)
43
+ Array(content_type_blacklist).any? { |item| content_type =~ /#{item}/ }
44
+ end
45
+
46
+ end # ContentTypeBlacklist
47
+ end # Uploader
48
+ end # CarrierWave
@@ -0,0 +1,48 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module ContentTypeWhitelist
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before :cache, :check_content_type_whitelist!
8
+ end
9
+
10
+ ##
11
+ # Override this method in your uploader to provide a whitelist of files content types
12
+ # which are allowed to be uploaded.
13
+ # Not only strings but Regexp are allowed as well.
14
+ #
15
+ # === Returns
16
+ #
17
+ # [NilClass, String, Regexp, Array[String, Regexp]] a whitelist of content types which are allowed to be uploaded
18
+ #
19
+ # === Examples
20
+ #
21
+ # def content_type_whitelist
22
+ # %w(text/json application/json)
23
+ # end
24
+ #
25
+ # Basically the same, but using a Regexp:
26
+ #
27
+ # def content_type_whitelist
28
+ # [/(text|application)\/json/]
29
+ # end
30
+ #
31
+ def content_type_whitelist; end
32
+
33
+ private
34
+
35
+ def check_content_type_whitelist!(new_file)
36
+ content_type = new_file.content_type
37
+ if content_type_whitelist && !whitelisted_content_type?(content_type)
38
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_whitelist_error", content_type: content_type)
39
+ end
40
+ end
41
+
42
+ def whitelisted_content_type?(content_type)
43
+ Array(content_type_whitelist).any? { |item| content_type =~ /#{item}/ }
44
+ end
45
+
46
+ end # ContentTypeWhitelist
47
+ end # Uploader
48
+ end # CarrierWave
@@ -11,6 +11,8 @@ require "carrierwave/uploader/download"
11
11
  require "carrierwave/uploader/remove"
12
12
  require "carrierwave/uploader/extension_whitelist"
13
13
  require "carrierwave/uploader/extension_blacklist"
14
+ require "carrierwave/uploader/content_type_whitelist"
15
+ require "carrierwave/uploader/content_type_blacklist"
14
16
  require "carrierwave/uploader/processing"
15
17
  require "carrierwave/uploader/versions"
16
18
  require "carrierwave/uploader/default_url"
@@ -53,6 +55,8 @@ module CarrierWave
53
55
  include CarrierWave::Uploader::Remove
54
56
  include CarrierWave::Uploader::ExtensionWhitelist
55
57
  include CarrierWave::Uploader::ExtensionBlacklist
58
+ include CarrierWave::Uploader::ContentTypeWhitelist
59
+ include CarrierWave::Uploader::ContentTypeBlacklist
56
60
  include CarrierWave::Uploader::Processing
57
61
  include CarrierWave::Uploader::Versions
58
62
  include CarrierWave::Uploader::DefaultUrl
@@ -1,3 +1,3 @@
1
1
  module CarrierWave
2
- VERSION = "0.11.0"
2
+ VERSION = "0.11.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-29 00:00:00.000000000 Z
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mimemagic
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.3.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.3.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: pg
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -292,6 +306,8 @@ files:
292
306
  - lib/carrierwave/uploader/cache.rb
293
307
  - lib/carrierwave/uploader/callbacks.rb
294
308
  - lib/carrierwave/uploader/configuration.rb
309
+ - lib/carrierwave/uploader/content_type_blacklist.rb
310
+ - lib/carrierwave/uploader/content_type_whitelist.rb
295
311
  - lib/carrierwave/uploader/default_url.rb
296
312
  - lib/carrierwave/uploader/download.rb
297
313
  - lib/carrierwave/uploader/extension_blacklist.rb
@@ -332,7 +348,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
332
348
  version: '0'
333
349
  requirements: []
334
350
  rubyforge_project: carrierwave
335
- rubygems_version: 2.4.3
351
+ rubygems_version: 2.4.5.1
336
352
  signing_key:
337
353
  specification_version: 3
338
354
  summary: Ruby file upload library