Skip to content

Commit 221937c

Browse files
committed
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
1 parent 859ca44 commit 221937c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

actionpack/lib/action_dispatch/http/mime_type.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def #{method}(*)
2323

2424
SET = Mimes.new
2525
EXTENSION_LOOKUP = {}
26-
LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k.blank? }
26+
LOOKUP = {}
2727

2828
class << self
2929
def [](type)
@@ -146,7 +146,7 @@ def register_callback(&block)
146146
end
147147

148148
def lookup(string)
149-
LOOKUP[string]
149+
LOOKUP[string] || Type.new(string)
150150
end
151151

152152
def lookup_by_extension(extension)
@@ -225,9 +225,12 @@ def unregister(symbol)
225225
end
226226
end
227227

228+
attr_reader :hash
229+
228230
def initialize(string, symbol = nil, synonyms = [])
229231
@symbol, @synonyms = symbol, synonyms
230232
@string = string
233+
@hash = [@string, @synonyms, @symbol].hash
231234
end
232235

233236
def to_s
@@ -261,6 +264,13 @@ def ==(mime_type)
261264
end
262265
end
263266

267+
def eql?(other)
268+
super || (self.class == other.class &&
269+
@string == other.string &&
270+
@synonyms == other.synonyms &&
271+
@symbol == other.symbol)
272+
end
273+
264274
def =~(mime_type)
265275
return false if mime_type.blank?
266276
regexp = Regexp.new(Regexp.quote(mime_type.to_s))
@@ -274,6 +284,10 @@ def html?
274284
end
275285

276286

287+
protected
288+
289+
attr_reader :string, :synonyms
290+
277291
private
278292

279293
def to_ary; end

0 commit comments

Comments
 (0)