Skip to content

Commit

Permalink
Fix sql log filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoFelipe committed Nov 30, 2023
1 parent ca75cfa commit baf1a6e
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions config/initializers/filter_parameter_logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,22 @@
:passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn,
]

# Override of render_bind to force a truncation of the binary column of carrier_wave_files
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/log_subscriber.rb#L86
# Override of ActiveRecord::LogSubscriber::sql to force the filtering of all sql queries that contain carrier_wave_files
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/log_subscriber.rb
module LogTruncater
def render_bind(attr, value)
case attr
when ActiveModel::Attribute
if attr.type.binary? && attr.value
value = "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>"
# new code
elsif attr.name.to_s == "binary" && attr.value
value = "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>"
# << end of new code
def sql(event)
payload = event.payload
sql = payload[:sql]
if sql.include? "carrier_wave_files" # filters out any sql that includes this table
if payload[:sql] =~ /\A\s*(\w+)/i
payload[:sql] = "#{$1} carrier_wave_files [SQL Filtered]"
else
payload[:sql] = "carrier_wave_files [SQL Filtered]"
end
when Array
attr = attr.first
else
attr = nil
end

[attr&.name, value]
result = self.method(:sql).super_method.call(event)
payload[:sql] = sql
return result
end
end

Expand Down

0 comments on commit baf1a6e

Please sign in to comment.