lib/secure_headers.rb
def override_content_security_policy_directives(request, additions, target = nil)
      config, target = config_and_target(request, target)

      if [:both, :enforced].include?(target)
        if config.csp.opt_out?
          config.csp = ContentSecurityPolicyConfig.new({})
        end

        config.csp.merge!(additions)
      end

      if [:both, :report_only].include?(target)
        if config.csp_report_only.opt_out?
          config.csp_report_only = ContentSecurityPolicyReportOnlyConfig.new({})
        end

        config.csp_report_only.merge!(additions)
      end

      override_secure_headers_request_config(request, config)
    end
# Public: override a given set of directives for the current request. If a
# value already exists for a given directive, it will be overridden.
#
# If CSP was previously OPT_OUT, a new blank policy is used.
#
# additions - a hash containing directives. e.g.
#    script_src: %w(another-host.com)
override a given set of directives for the current request. If a
value already exists for a given directive, it will be overridden.

If CSP was previously OPT_OUT, a new blank policy is used.

a hash containing directives.
override a given set of directives for the current request . If a value already exists for a given directive it will be overridden . If CSP was previously OPT_OUT a new blank policy is used . a hash containing directives .
def override_content_security_policy_directives(request, additions, target = nil)
      config, target = config_and_target(request, target)
      if [:both, :enforced].include?(target)
        if config.csp.opt_out?
          config.csp = ContentSecurityPolicyConfig.new({})
        end
        config.csp.merge!(additions)
      end
      if [:both, :report_only].include?(target)
        if config.csp_report_only.opt_out?
          config.csp_report_only = ContentSecurityPolicyReportOnlyConfig.new({})
        end
        config.csp_report_only.merge!(additions)
      end
      override_secure_headers_request_config(request, config)
    end
def override_content_security_policy_directives ( request , additions , target = nil ) config , target = config_and_target ( request , target ) if [ :both , :enforced ] . include? ( target ) if config . csp . opt_out? config . csp = ContentSecurityPolicyConfig . new ( { } ) end config . csp . merge! ( additions ) end if [ :both , :report_only ] . include? ( target ) if config . csp_report_only . opt_out? config . csp_report_only = ContentSecurityPolicyReportOnlyConfig . new ( { } ) end config . csp_report_only . merge! ( additions ) end override_secure_headers_request_config ( request , config ) end
Public: override a given set of directives for the current request.
Public : override a given set of directives for the current request .
request
additions
target