Sha256: 9f9972e47b6caf5d32b9fa8ff7783bac442b5d84ce19d74b42c1c3e3fbf1014d

Contents?: true

Size: 1.3 KB

Versions: 22

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

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

    include AbstractController::Helpers
    include AbstractController::Callbacks

    included do
      helper_method :content_security_policy?
      helper_method :content_security_policy_nonce
    end

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

          unless enabled
            request.content_security_policy = nil
          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

    private
      def content_security_policy?
        request.content_security_policy
      end

      def content_security_policy_nonce
        request.content_security_policy_nonce
      end

      def current_content_security_policy
        request.content_security_policy.try(:clone) || ActionDispatch::ContentSecurityPolicy.new
      end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
actionpack-6.0.6.1 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.6 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.5.1 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.5 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.4.8 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.4.7 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.4.6 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.4.5 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.4.4 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.4.3 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.4.2 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.4.1 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.4 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.3.7 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.3.6 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.3.5 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.3.4 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.3.3 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.3.2 lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.3.1 lib/action_controller/metal/content_security_policy.rb