Skip to content

Commit

Permalink
SECURITY: do not follow redirect by default when downloading hotlinke…
Browse files Browse the repository at this point in the history
…d images
  • Loading branch information
ZogStriP committed Jul 27, 2014
1 parent 621b86d commit 488d4ee
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/file_helper.rb
Expand Up @@ -6,15 +6,15 @@ def self.is_image?(filename)
filename =~ images_regexp
end

def self.download(url, max_file_size, tmp_file_name)
def self.download(url, max_file_size, tmp_file_name, follow_redirect=false)
raise Discourse::InvalidParameters.new(:url) unless url =~ /^https?:\/\//

uri = URI.parse(url)
extension = File.extname(uri.path)
tmp = Tempfile.new([tmp_file_name, extension])

File.open(tmp.path, "wb") do |f|
downloaded = uri.open("rb", read_timeout: 5)
downloaded = uri.open("rb", read_timeout: 5, redirect: follow_redirect)
while f.size <= max_file_size && data = downloaded.read(max_file_size)
f.write(data)
end
Expand Down

0 comments on commit 488d4ee

Please sign in to comment.