Fix media host not being included in connect-src for OCR (#11577)

signup-info-prompt
Eugen Rochko 2019-08-16 01:54:36 +02:00 committed by GitHub
parent 8fdff2748f
commit b7f5f0ec10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 4 deletions

View File

@ -2,9 +2,19 @@
# For further information see the following documentation # For further information see the following documentation
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
base_host = Rails.configuration.x.web_domain def host_to_url(str)
"http#{Rails.configuration.x.use_https ? 's' : ''}://#{str}" unless str.blank?
end
base_host = Rails.configuration.x.web_domain
assets_host = Rails.configuration.action_controller.asset_host assets_host = Rails.configuration.action_controller.asset_host
assets_host ||= "http#{Rails.configuration.x.use_https ? 's' : ''}://#{base_host}" assets_host ||= host_to_url(base_host)
media_host = host_to_url(ENV['S3_ALIAS_HOST'])
media_host ||= host_to_url(ENV['S3_CLOUDFRONT_HOST'])
media_host ||= host_to_url(ENV['S3_HOSTNAME']) if ENV['S3_ENABLED'] == 'true'
media_host ||= assets_host
Rails.application.config.content_security_policy do |p| Rails.application.config.content_security_policy do |p|
p.base_uri :none p.base_uri :none
@ -20,10 +30,10 @@ Rails.application.config.content_security_policy do |p|
if Rails.env.development? if Rails.env.development?
webpacker_urls = %w(ws http).map { |protocol| "#{protocol}#{Webpacker.dev_server.https? ? 's' : ''}://#{Webpacker.dev_server.host_with_port}" } webpacker_urls = %w(ws http).map { |protocol| "#{protocol}#{Webpacker.dev_server.https? ? 's' : ''}://#{Webpacker.dev_server.host_with_port}" }
p.connect_src :self, :data, :blob, assets_host, Rails.configuration.x.streaming_api_base_url, *webpacker_urls p.connect_src :self, :data, :blob, assets_host, media_host, Rails.configuration.x.streaming_api_base_url, *webpacker_urls
p.script_src :self, :blob, :unsafe_inline, :unsafe_eval, assets_host p.script_src :self, :blob, :unsafe_inline, :unsafe_eval, assets_host
else else
p.connect_src :self, :data, :blob, assets_host, Rails.configuration.x.streaming_api_base_url p.connect_src :self, :data, :blob, assets_host, media_host, Rails.configuration.x.streaming_api_base_url
p.script_src :self, :blob, assets_host p.script_src :self, :blob, assets_host
end end
end end