|
2 | 2 | # For further information see the following documentation |
3 | 3 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy |
4 | 4 |
|
5 | | -base_host = Rails.configuration.x.web_domain |
| 5 | +def host_to_url(str) |
| 6 | + "http#{Rails.configuration.x.use_https ? 's' : ''}://#{str}" unless str.blank? |
| 7 | +end |
| 8 | + |
| 9 | +base_host = Rails.configuration.x.web_domain |
| 10 | + |
6 | 11 | assets_host = Rails.configuration.action_controller.asset_host |
7 | | -assets_host ||= "http#{Rails.configuration.x.use_https ? 's' : ''}://#{base_host}" |
8 | 12 | instance_ticker_host = "https://wee.jp" |
| 13 | +assets_host ||= host_to_url(base_host) |
| 14 | + |
| 15 | +media_host = host_to_url(ENV['S3_ALIAS_HOST']) |
| 16 | +media_host ||= host_to_url(ENV['S3_CLOUDFRONT_HOST']) |
| 17 | +media_host ||= host_to_url(ENV['S3_HOSTNAME']) if ENV['S3_ENABLED'] == 'true' |
| 18 | +media_host ||= assets_host |
9 | 19 |
|
10 | 20 | Rails.application.config.content_security_policy do |p| |
11 | 21 | p.base_uri :none |
|
21 | 31 | if Rails.env.development? |
22 | 32 | webpacker_urls = %w(ws http).map { |protocol| "#{protocol}#{Webpacker.dev_server.https? ? 's' : ''}://#{Webpacker.dev_server.host_with_port}" } |
23 | 33 |
|
24 | | - p.connect_src :self, :data, :blob, assets_host, Rails.configuration.x.streaming_api_base_url, *webpacker_urls |
| 34 | + p.connect_src :self, :data, :blob, assets_host, media_host, Rails.configuration.x.streaming_api_base_url, *webpacker_urls |
25 | 35 | p.script_src :self, :blob, :unsafe_inline, :unsafe_eval, assets_host |
26 | 36 | else |
27 | | - p.connect_src :self, :data, :blob, assets_host, Rails.configuration.x.streaming_api_base_url |
| 37 | + p.connect_src :self, :data, :blob, assets_host, media_host, Rails.configuration.x.streaming_api_base_url |
28 | 38 | p.script_src :self, :blob, assets_host |
29 | 39 | end |
30 | 40 | end |
|
0 commit comments