Created
October 27, 2011 08:53
-
-
Save vraravam/1319094 to your computer and use it in GitHub Desktop.
ActiveResource filter logging of sensitive params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_resource/base' | |
require 'active_resource/log_subscriber' | |
module ActiveResource | |
class LogSubscriber < ActiveSupport::LogSubscriber | |
def request_with_filtered_logging(event) | |
request_uri = event.payload[:request_uri] | |
start_of_query_string = request_uri.index("?") | |
request_uri_without_query_string = request_uri[0, start_of_query_string] | |
query_string = request_uri[(start_of_query_string + 1)..-1] | |
query_hash = Rack::Utils.parse_nested_query(query_string).with_indifferent_access | |
Rails.configuration.filter_parameters.each { |param| query_hash[param] = "[FILTERED]" if query_hash.has_key?(param) } | |
event.payload[:request_uri] = "#{request_uri_without_query_string}?#{query_hash.to_query}" | |
request_without_filtered_logging(event) | |
end | |
alias_method_chain :request, :filtered_logging | |
end | |
end | |
ActiveResource::Base.logger = Rails.logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment