2021-10-13 14:12:40 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module OneTrustCSP
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
content_security_policy do |policy|
|
2021-11-04 23:12:26 -04:00
|
|
|
next unless helpers.one_trust_enabled? || policy.directives.present?
|
2021-10-13 14:12:40 -04:00
|
|
|
|
|
|
|
default_script_src = policy.directives['script-src'] || policy.directives['default-src']
|
2021-12-06 10:14:39 -05:00
|
|
|
script_src_values = Array.wrap(default_script_src) | ["'unsafe-eval'", 'https://cdn.cookielaw.org', 'https://*.onetrust.com']
|
2021-10-13 14:12:40 -04:00
|
|
|
policy.script_src(*script_src_values)
|
|
|
|
|
|
|
|
default_connect_src = policy.directives['connect-src'] || policy.directives['default-src']
|
2021-12-06 10:14:39 -05:00
|
|
|
connect_src_values = Array.wrap(default_connect_src) | ['https://cdn.cookielaw.org', 'https://*.onetrust.com']
|
2021-10-13 14:12:40 -04:00
|
|
|
policy.connect_src(*connect_src_values)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|