Sha256: f3aa821d460896c7965a94422bd4e4c68039dfd05f4904361e4ff1d684638eb5

Contents?: true

Size: 1.31 KB

Versions: 111

Compression:

Stored size: 1.31 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

111 entries across 103 versions & 7 rubygems

Version Path
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_controller/metal/content_security_policy.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.0 lib/action_controller/metal/content_security_policy.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/content_security_policy.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/content_security_policy.rb
spiral_form-0.1.1 vendor/bundle/gems/actionpack-5.2.3/lib/action_controller/metal/content_security_policy.rb
spiral_form-0.1.0 vendor/bundle/gems/actionpack-5.2.3/lib/action_controller/metal/content_security_policy.rb
actionpack-6.0.0.rc2 lib/action_controller/metal/content_security_policy.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/content_security_policy.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/content_security_policy.rb
jets-1.9.7 vendor/rails/actionpack/lib/action_controller/metal/content_security_policy.rb
jets-1.9.6 vendor/rails/actionpack/lib/action_controller/metal/content_security_policy.rb
jets-1.9.5 vendor/rails/actionpack/lib/action_controller/metal/content_security_policy.rb
jets-1.9.4 vendor/rails/actionpack/lib/action_controller/metal/content_security_policy.rb
jets-1.9.3 vendor/rails/actionpack/lib/action_controller/metal/content_security_policy.rb
jets-1.9.2 vendor/rails/actionpack/lib/action_controller/metal/content_security_policy.rb
jets-1.9.1 vendor/rails/actionpack/lib/action_controller/metal/content_security_policy.rb
jets-1.9.0 vendor/rails/actionpack/lib/action_controller/metal/content_security_policy.rb
jets-1.8.14 vendor/rails/actionpack/lib/action_controller/metal/content_security_policy.rb
jets-1.8.13 vendor/rails/actionpack/lib/action_controller/metal/content_security_policy.rb