Module: ActiveRecord::PGCrypto::LogSubscriber

Defined in:
lib/active_record/pgcrypto/log_subscriber.rb

Overview

Subscribes to the logger and obfuscates the sensitive queries.

Constant Summary collapse

REGEXP =

rubocop:disable Lint/MixedRegexpCaptureTypes

/(\(*)(?<operation>pgp_sym_(decrypt|encrypt)_bytea)(\(+.*\)+)/im.freeze
PLACEHOLDER =

rubocop:enable Lint/MixedRegexpCaptureTypes

'[FILTERED]'.freeze

Instance Method Summary collapse

Instance Method Details

#sql(event) ⇒ NilClass

Scrubs the log event from any sensitive SQL

Returns:

  • (NilClass)


14
15
16
17
18
19
20
21
22
# File 'lib/active_record/pgcrypto/log_subscriber.rb', line 14

def sql(event)
  scrubbed_sql = event.payload[:sql].gsub(REGEXP) do |_|
    "#{$LAST_MATCH_INFO[:operation]}(#{PLACEHOLDER})"
  end

  event.payload[:sql] = scrubbed_sql

  super(event)
end