A platform for community discussion. Free, open, simple.
minor changes to default script-src (#6770)
Kyle Zhaob0c2e9bb051b
diff --git a/lib/content_security_policy/default.rb b/lib/content_security_policy/default.rbindex 46a543f7ed2..d92285af43a 100644--- a/lib/content_security_policy/default.rb+++ b/lib/content_security_policy/default.rb@@ -44,13 +44,14 @@ class ContentSecurityPolicydef script_src[:unsafe_eval,+ :report_sample,"#{base_url}/logs/","#{base_url}/sidekiq/","#{base_url}/mini-profiler-resources/",*script_assets].tap do |sources|- sources << 'https://www.google-analytics.com' if SiteSetting.ga_universal_tracking_code.present?- sources << 'https://www.googletagmanager.com' if SiteSetting.gtm_container_id.present?+ sources << 'https://www.google-analytics.com/analytics.js' if SiteSetting.ga_universal_tracking_code.present?+ sources << 'https://www.googletagmanager.com/gtm.js' if SiteSetting.gtm_container_id.present?endenddiff --git a/spec/lib/content_security_policy_spec.rb b/spec/lib/content_security_policy_spec.rbindex 40f618d2e37..79f190e588f 100644--- a/spec/lib/content_security_policy_spec.rb+++ b/spec/lib/content_security_policy_spec.rb@@ -31,6 +31,7 @@ describe ContentSecurityPolicy doscript_srcs = parse(policy)['script-src']expect(script_srcs).to include(*%w['unsafe-eval'+ 'report-sample'http://test.localhost/logs/http://test.localhost/sidekiq/http://test.localhost/mini-profiler-resources/@@ -50,8 +51,8 @@ describe ContentSecurityPolicy doSiteSetting.gtm_container_id = 'GTM-ABCDEF'script_srcs = parse(policy)['script-src']- expect(script_srcs).to include('https://www.google-analytics.com')- expect(script_srcs).to include('https://www.googletagmanager.com')+ expect(script_srcs).to include('https://www.google-analytics.com/analytics.js')+ expect(script_srcs).to include('https://www.googletagmanager.com/gtm.js')endit 'whitelists CDN assets when integrated' do