diff options
Diffstat (limited to 'app/controllers/concerns/google_syndication_csp.rb')
-rw-r--r-- | app/controllers/concerns/google_syndication_csp.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/controllers/concerns/google_syndication_csp.rb b/app/controllers/concerns/google_syndication_csp.rb new file mode 100644 index 00000000000..c55debe448b --- /dev/null +++ b/app/controllers/concerns/google_syndication_csp.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module GoogleSyndicationCSP + extend ActiveSupport::Concern + + ALLOWED_SRC = ['*.google.com/pagead/landing', 'pagead2.googlesyndication.com/pagead/landing'].freeze + + included do + content_security_policy do |policy| + next unless helpers.google_tag_manager_enabled? || policy.directives.present? + + connect_src_values = Array.wrap( + policy.directives['connect-src'] || policy.directives['default-src'] + ) + + connect_src_values.concat(ALLOWED_SRC) if helpers.google_tag_manager_enabled? + + policy.connect_src(*connect_src_values.uniq) + end + end +end |