Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tenderlove committed Jan 22, 2016
1 parent 036bbda commit 37047b7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions actionpack/lib/action_dispatch/http/mime_type.rb
Expand Up @@ -23,7 +23,7 @@ def #{method}(*)

SET = Mimes.new
EXTENSION_LOOKUP = {}
LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k.blank? }
LOOKUP = {}

class << self
def [](type)
Expand Down Expand Up @@ -146,7 +146,7 @@ def register_callback(&block)
end

def lookup(string)
LOOKUP[string]
LOOKUP[string] || Type.new(string)
end

def lookup_by_extension(extension)
Expand Down Expand Up @@ -225,9 +225,12 @@ def unregister(symbol)
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
Expand Down Expand Up @@ -261,6 +264,13 @@ def ==(mime_type)
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 if mime_type.blank?
regexp = Regexp.new(Regexp.quote(mime_type.to_s))
Expand All @@ -274,6 +284,10 @@ def html?
end


protected

attr_reader :string, :synonyms

private

def to_ary; end
Expand Down

0 comments on commit 37047b7

Please sign in to comment.