Sha256: a36633677721575d24a04c025d66a671dc684320024d08f6e08102e636051dde

Contents?: true

Size: 609 Bytes

Versions: 1

Compression:

Stored size: 609 Bytes

Contents

module ActiveRecord
  module PGCrypto
    # Subscribes to the logger and obfuscates the sensitive queries.
    module LogSubscriber
      # rubocop:disable Lint/MixedRegexpCaptureTypes
      REGEXP = \
        /(\(*)(?<operation>pgp_sym_(decrypt|encrypt)_bytea)(\(+.*\)+)/im.freeze
      # rubocop:enable Lint/MixedRegexpCaptureTypes
      PLACEHOLDER = '[FILTERED]'.freeze

      # Scrubs the log event from any sensitive SQL
      #
      # @return [NilClass]
      def sql(event)
        event.payload[:sql] = event.payload[:sql].gsub(REGEXP, PLACEHOLDER)

        super(event)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_record-pgcrypto-0.2.6 lib/active_record/pgcrypto/log_subscriber.rb