aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2016-01-11 14:36:49 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2016-01-22 15:00:31 -0800
commit51313c21a63c3ed47ba20df3ad7f26a45d5bf684 (patch)
treeff42c41899c53deb26f047c6cb077c6dd434a042
parent17e6f1507b7f2c2a883c180f4f9548445d6dfbda (diff)
downloadrails-51313c21a63c3ed47ba20df3ad7f26a45d5bf684.tar.gz
rails-51313c21a63c3ed47ba20df3ad7f26a45d5bf684.tar.bz2
rails-51313c21a63c3ed47ba20df3ad7f26a45d5bf684.zip
stop caching mime types globally
Unknown mime types should not be cached globally. This global cache leads to a memory leak and a denial of service vulnerability. CVE-2016-0751
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index b8d395854c..6abbf9c754 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -31,7 +31,7 @@ module Mime
SET = Mimes.new
EXTENSION_LOOKUP = {}
- LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k.blank? }
+ LOOKUP = {}
class << self
def [](type)
@@ -177,7 +177,7 @@ module Mime
end
def lookup(string)
- LOOKUP[string]
+ LOOKUP[string] || Type.new(string)
end
def lookup_by_extension(extension)
@@ -255,9 +255,12 @@ module Mime
end
end
+ attr_reader :hash
+
def initialize(string, symbol = nil, synonyms = [])
@symbol, @synonyms = symbol, synonyms
@string = string
+ @hash = [@string, @synonyms, @symbol].hash
end
def to_s
@@ -291,6 +294,13 @@ module Mime
end
end
+ def eql?(other)
+ super || (self.class == other.class &&
+ @string == other.string &&
+ @synonyms == other.synonyms &&
+ @symbol == other.symbol)
+ end
+
def =~(mime_type)
return false unless mime_type
regexp = Regexp.new(Regexp.quote(mime_type.to_s))
@@ -303,6 +313,10 @@ module Mime
def all?; false; end
+ protected
+
+ attr_reader :string, :synonyms
+
private
def to_ary; end