Fix #3528: Prevent CloudFlare from altering images.

This commit is contained in:
evazion
2018-02-17 11:43:27 -06:00
parent 1eff41a6f9
commit 263fd0eef1
2 changed files with 15 additions and 1 deletions

View File

@@ -36,7 +36,7 @@ module Downloads
url, headers, @data = before_download(@source, @data)
::File.open(@file_path, "wb") do |out|
http_get_streaming(url, headers) do |response|
http_get_streaming(uncached_url(url), headers) do |response|
out.write(response)
end
end
@@ -55,6 +55,13 @@ module Downloads
return [url, headers, datums]
end
# Prevent transparent proxies (namely Cloudflare) from potentially mangling the image. See issue #3528.
def uncached_url(url)
url = Addressable::URI.parse(url)
url.query_values = (url.query_values || {}).merge(danbooru_no_cache: SecureRandom.uuid)
url
end
def after_download(src)
src = fix_twitter_sources(src)
if options[:referer_url].present?