diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2019-08-16 01:54:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-16 01:54:36 +0200 |
commit | b7f5f0ec101d3ba13e7490f6526af6fedd4fa0be (patch) | |
tree | cc9640336e0789e466b54fdfde45d19e9ab08466 | |
parent | 8fdff2748ffbc4ce3d36c75f2bd33182b641e895 (diff) |
Fix media host not being included in connect-src for OCR (#11577)
-rw-r--r-- | config/initializers/content_security_policy.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 56e997933..2dbc15a8d 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -2,9 +2,19 @@ # For further information see the following documentation # 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 ||= "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| p.base_uri :none @@ -20,10 +30,10 @@ Rails.application.config.content_security_policy do |p| if Rails.env.development? 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 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 end end |