carrierwave 0.10.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: 0092635d7d29c1b3f6b16b2589e48ba6919ff0b9
4
- data.tar.gz: c19c7734e547d39cfec1d90aa48fb28bd3d99b2a
3
+ metadata.gz: 8c1689fd908e56b671c45e5cb1eebe3ec938a4df
4
+ data.tar.gz: 89668d77484c786139f513dc1b82c82879da4e11
5
5
  SHA512:
6
- metadata.gz: d4cce1995281a15422ac6c35b82b19b54e6ba0f5d0efffcbf6c9d3e7f81ae462efa8f313a84ba707bdf4a5e4938e7b367fae90789e18dc24421b023b64c77506
7
- data.tar.gz: 5b103922747f4fb1f1c2a172408e9904a39930eda9cd1769ca0b9ba16ee7bbed4dbb9aa1d3a24ac8e61a19ead8491e4ed5b4bca852224f33e6b8b02a90f7d7da
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
@@ -62,6 +62,8 @@ module CarrierWave
62
62
 
63
63
  included do
64
64
  begin
65
+ require "rmagick"
66
+ rescue LoadError
65
67
  require "RMagick"
66
68
  rescue LoadError => e
67
69
  e.message << " (You may need to install the rmagick gem)"
@@ -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)
@@ -8,15 +8,27 @@ module CarrierWave
8
8
  end
9
9
  end
10
10
 
11
+ class CacheCounter
12
+ @@counter = 0
13
+
14
+ def self.increment
15
+ @@counter += 1
16
+ end
17
+ end
18
+
11
19
  ##
12
20
  # Generates a unique cache id for use in the caching system
13
21
  #
14
22
  # === Returns
15
23
  #
16
- # [String] a cache id in the format TIMEINT-PID-RND
24
+ # [String] a cache id in the format TIMEINT-PID-COUNTER-RND
17
25
  #
18
26
  def self.generate_cache_id
19
- Time.now.utc.to_i.to_s + '-' + Process.pid.to_s + '-' + ("%04d" % rand(9999))
27
+ [Time.now.utc.to_i,
28
+ Process.pid,
29
+ '%04d' % (CarrierWave::CacheCounter.increment % 1000),
30
+ '%04d' % rand(9999)
31
+ ].map(&:to_s).join('-')
20
32
  end
21
33
 
22
34
  module Uploader
@@ -91,7 +103,7 @@ module CarrierWave
91
103
  #
92
104
  # === Returns
93
105
  #
94
- # [String] a cache name, in the format YYYYMMDD-HHMM-PID-RND/filename.txt
106
+ # [String] a cache name, in the format TIMEINT-PID-COUNTER-RND/filename.txt
95
107
  #
96
108
  def cache_name
97
109
  File.join(cache_id, full_original_filename) if cache_id and original_filename
@@ -165,7 +177,9 @@ module CarrierWave
165
177
  alias_method :full_original_filename, :original_filename
166
178
 
167
179
  def cache_id=(cache_id)
168
- raise CarrierWave::InvalidParameter, "invalid cache id" unless cache_id =~ /\A[\d]+\-[\d]+\-[\d]{4}\z/
180
+ # Earlier version used 3 part cache_id. Thus we should allow for
181
+ # the cache_id to have both 3 part and 4 part formats.
182
+ raise CarrierWave::InvalidParameter, "invalid cache id" unless cache_id =~ /\A[\d]+\-[\d]+(\-[\d]{4})?\-[\d]{4}\z/
169
183
  @cache_id = cache_id
170
184
  end
171
185
 
@@ -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.10.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.10.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: 2014-02-26 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
@@ -67,7 +67,21 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.16'
69
69
  - !ruby/object:Gem::Dependency
70
- name: mysql2
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
83
+ - !ruby/object:Gem::Dependency
84
+ name: pg
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -138,18 +152,46 @@ dependencies:
138
152
  version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: fog
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 1.20.0
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 1.20.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: unf
141
169
  requirement: !ruby/object:Gem::Requirement
142
170
  requirements:
143
171
  - - ">="
144
172
  - !ruby/object:Gem::Version
145
- version: 1.3.1
173
+ version: '0'
146
174
  type: :development
147
175
  prerelease: false
148
176
  version_requirements: !ruby/object:Gem::Requirement
149
177
  requirements:
150
178
  - - ">="
151
179
  - !ruby/object:Gem::Version
152
- version: 1.3.1
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: net-ssh
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 2.9.0
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 2.9.0
153
195
  - !ruby/object:Gem::Dependency
154
196
  name: mini_magick
155
197
  requirement: !ruby/object:Gem::Requirement
@@ -264,6 +306,8 @@ files:
264
306
  - lib/carrierwave/uploader/cache.rb
265
307
  - lib/carrierwave/uploader/callbacks.rb
266
308
  - lib/carrierwave/uploader/configuration.rb
309
+ - lib/carrierwave/uploader/content_type_blacklist.rb
310
+ - lib/carrierwave/uploader/content_type_whitelist.rb
267
311
  - lib/carrierwave/uploader/default_url.rb
268
312
  - lib/carrierwave/uploader/download.rb
269
313
  - lib/carrierwave/uploader/extension_blacklist.rb
@@ -304,7 +348,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
304
348
  version: '0'
305
349
  requirements: []
306
350
  rubyforge_project: carrierwave
307
- rubygems_version: 2.2.0
351
+ rubygems_version: 2.4.5.1
308
352
  signing_key:
309
353
  specification_version: 3
310
354
  summary: Ruby file upload library