mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:49:06 +08:00
FIX: Always allow downloads from CDN
This commit is contained in:
parent
f101e052e6
commit
3b0cbf7013
|
@ -11,13 +11,14 @@ class FileHelper
|
|||
url = "https:" + url if url.start_with?("//")
|
||||
raise Discourse::InvalidParameters.new(:url) unless url =~ /^https?:\/\//
|
||||
|
||||
# uri = FinalDestination.new(url).resolve
|
||||
uri = URI.parse(url)
|
||||
uri = FinalDestination.new(url, max_redirects: follow_redirect ? 5 : 1).resolve
|
||||
return unless uri.present?
|
||||
|
||||
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: read_timeout, redirect: follow_redirect, allow_redirections: :all)
|
||||
downloaded = uri.open("rb", read_timeout: read_timeout)
|
||||
while f.size <= max_file_size && data = downloaded.read(512.kilobytes)
|
||||
f.write(data)
|
||||
end
|
||||
|
|
|
@ -77,6 +77,15 @@ class FinalDestination
|
|||
end
|
||||
|
||||
def is_dest_valid?
|
||||
|
||||
# CDNs are always allowed
|
||||
return true if SiteSetting.s3_cdn_url.present? &&
|
||||
@uri.hostname == URI(SiteSetting.s3_cdn_url).hostname
|
||||
|
||||
global_cdn = GlobalSetting.try(:cdn_url)
|
||||
return true if global_cdn.present? &&
|
||||
@uri.hostname == URI(global_cdn).hostname
|
||||
|
||||
return false unless @uri && @uri.host
|
||||
|
||||
address_s = @opts[:lookup_ip].call(@uri.hostname)
|
||||
|
|
|
@ -57,7 +57,6 @@ describe FinalDestination do
|
|||
expect(final.redirected?).to eq(false)
|
||||
expect(final.status).to eq(:resolved)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "underscores in URLs" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user