aboutsummaryrefslogblamecommitdiffstats
path: root/actionpack/lib/action_controller/metal/content_security_policy.rb
blob: 48a7109bea4bd63df679b17dbcb0dc93caa35eba (plain) (tree)

























                                                                            
# frozen_string_literal: true

module ActionController #:nodoc:
  module ContentSecurityPolicy
    # TODO: Documentation
    extend ActiveSupport::Concern

    module ClassMethods
      def content_security_policy(**options, &block)
        before_action(options) do
          if block_given?
            policy = request.content_security_policy.clone
            yield policy
            request.content_security_policy = policy
          end
        end
      end

      def content_security_policy_report_only(report_only = true, **options)
        before_action(options) do
          request.content_security_policy_report_only = report_only
        end
      end
    end
  end
end