Sha256: 0410087d08a13f196ec767d3fbf8e31a3037d23d6c0e8c7aa8148479147ca95b

Contents?: true

Size: 1.3 KB

Versions: 37

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&.clone || ActionDispatch::ContentSecurityPolicy.new
      end
  end
end

Version data entries

37 entries across 37 versions & 4 rubygems

Version Path
actionpack-6.1.4.4 lib/action_controller/metal/content_security_policy.rb
actionpack-6.1.4.3 lib/action_controller/metal/content_security_policy.rb
actionpack-6.1.4.2 lib/action_controller/metal/content_security_policy.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/actionpack-6.1.4.1/lib/action_controller/metal/content_security_policy.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/actionpack-6.1.4.1/lib/action_controller/metal/content_security_policy.rb
actionpack-6.1.4.1 lib/action_controller/metal/content_security_policy.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.4/lib/action_controller/metal/content_security_policy.rb
actionpack-6.1.4 lib/action_controller/metal/content_security_policy.rb
actionpack-6.1.3.2 lib/action_controller/metal/content_security_policy.rb
actionpack-6.1.3.1 lib/action_controller/metal/content_security_policy.rb
actionpack-6.1.3 lib/action_controller/metal/content_security_policy.rb
actionpack-6.1.2.1 lib/action_controller/metal/content_security_policy.rb
actionpack-6.1.2 lib/action_controller/metal/content_security_policy.rb
actionpack-6.1.1 lib/action_controller/metal/content_security_policy.rb
actionpack-6.1.0 lib/action_controller/metal/content_security_policy.rb
actionpack-6.1.0.rc2 lib/action_controller/metal/content_security_policy.rb
actionpack-6.1.0.rc1 lib/action_controller/metal/content_security_policy.rb