Skip to content

Commit

Permalink
[tuning] Enable Cloudflare RUM by CSP settings update
Browse files Browse the repository at this point in the history
  • Loading branch information
highemerly committed Nov 18, 2023
1 parent 1d61713 commit 6c8f126
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions config/initializers/content_security_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def host_to_url(str)
media_host ||= host_to_url(ENV['S3_HOSTNAME']) if ENV['S3_ENABLED'] == 'true'
media_host ||= assets_host

cloudflare_insights_script_host = 'https://static.cloudflareinsights.com'
cloudflare_insights_connect_host = 'https://cloudflareinsights.com'
cloudflare_mirage_script_host = 'https://ajax.cloudflare.com'

def sso_host
return unless ENV['ONE_CLICK_SSO_LOGIN'] == 'true'
return unless ENV['OMNIAUTH_ONLY'] == 'true'
Expand Down Expand Up @@ -61,11 +65,11 @@ def sso_host
webpacker_public_host = ENV.fetch('WEBPACKER_DEV_SERVER_PUBLIC', Webpacker.config.dev_server[:public])
webpacker_urls = %w(ws http).map { |protocol| "#{protocol}#{Webpacker.dev_server.https? ? 's' : ''}://#{webpacker_public_host}" }

p.connect_src :self, :data, :blob, assets_host, media_host, Rails.configuration.x.streaming_api_base_url, *webpacker_urls
p.connect_src :self, :data, :blob, assets_host, media_host, cloudflare_insights_connect_host, Rails.configuration.x.streaming_api_base_url, *webpacker_urls
p.script_src :self, :unsafe_inline, :unsafe_eval, assets_host
else
p.connect_src :self, :data, :blob, assets_host, media_host, Rails.configuration.x.streaming_api_base_url
p.script_src :self, assets_host, "'wasm-unsafe-eval'"
p.script_src :self, assets_host, cloudflare_insights_script_host, cloudflare_mirage_script_host, "'wasm-unsafe-eval'"
end
end

Expand Down

0 comments on commit 6c8f126

Please sign in to comment.