From 6e46c0a8e0f3ab66acf4b968cbc89e0a20a762ba Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 28 Feb 2017 16:29:53 +0200 Subject: [PATCH 1/4] Filter EPP query "legalDocument" tag content when logging #314 --- config/application.rb | 3 +++ config/environments/production.rb | 3 --- lib/registry_log_formatter.rb | 13 +++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 lib/registry_log_formatter.rb diff --git a/config/application.rb b/config/application.rb index 109fa4d1ba..f366f084b0 100644 --- a/config/application.rb +++ b/config/application.rb @@ -10,6 +10,7 @@ require 'csv' require 'rails/all' # require "rails/test_unit/railtie" +require_relative '../lib/registry_log_formatter' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. @@ -78,6 +79,8 @@ class Application < Rails::Application domain: ENV['smtp_domain'], openssl_verify_mode: ENV['smtp_openssl_verify_mode'] } + + config.log_formatter = RegistryLogFormatter.new # Only works if placed in application.rb end end diff --git a/config/environments/production.rb b/config/environments/production.rb index 0c8989a3bb..e0f14e1ea7 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -75,9 +75,6 @@ # Disable automatic flushing of the log to improve performance. # config.autoflush_log = false - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new - # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end diff --git a/lib/registry_log_formatter.rb b/lib/registry_log_formatter.rb new file mode 100644 index 0000000000..4ce229156d --- /dev/null +++ b/lib/registry_log_formatter.rb @@ -0,0 +1,13 @@ +class RegistryLogFormatter < ::Logger::Formatter + def call(severity, timestamp, progname, msg) + msg = filter_epp_legal_document(msg) + "#{msg}\n" + end + + private + + def filter_epp_legal_document(msg) + msg.gsub(/]+)>([^<])+<\/eis:legalDocument>/, + "[FILTERED]") + end +end From 416f3810d2f14f91344bb501eec62b4879a0041e Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 28 Feb 2017 16:30:28 +0200 Subject: [PATCH 2/4] Cleanup log initializer #314 --- config/initializers/filter_parameter_logging.rb | 8 -------- config/initializers/log.rb | 3 +++ 2 files changed, 3 insertions(+), 8 deletions(-) delete mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/initializers/log.rb diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb deleted file mode 100644 index 30327efd50..0000000000 --- a/config/initializers/filter_parameter_logging.rb +++ /dev/null @@ -1,8 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [:password] - -Rails.application.config.filter_parameters << lambda do |key, value| - value.to_s.gsub!(/pw>.+<\//, 'pw>[FILTERED] Date: Wed, 1 Mar 2017 10:27:35 +0200 Subject: [PATCH 3/4] Restore EPP element log filter #314 --- config/initializers/filter_parameter_logging.rb | 6 ++++++ config/initializers/log.rb | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 config/initializers/filter_parameter_logging.rb delete mode 100644 config/initializers/log.rb diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000000..fb8784c3fe --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,6 @@ +Rails.application.configure do + config.filter_parameters += [:password, :nokogiri_frame, :parsed_frame] + config.filter_parameters << lambda do |key, value| + value.to_s.gsub!(/pw>.+<\//, 'pw>[FILTERED] Date: Wed, 1 Mar 2017 23:13:40 +0200 Subject: [PATCH 4/4] Filter EPP XML legalDocument tag #314 --- config/application.rb | 3 --- config/environments/production.rb | 3 +++ config/initializers/filter_parameter_logging.rb | 8 ++++++-- lib/registry_log_formatter.rb | 13 ------------- 4 files changed, 9 insertions(+), 18 deletions(-) delete mode 100644 lib/registry_log_formatter.rb diff --git a/config/application.rb b/config/application.rb index f366f084b0..109fa4d1ba 100644 --- a/config/application.rb +++ b/config/application.rb @@ -10,7 +10,6 @@ require 'csv' require 'rails/all' # require "rails/test_unit/railtie" -require_relative '../lib/registry_log_formatter' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. @@ -79,8 +78,6 @@ class Application < Rails::Application domain: ENV['smtp_domain'], openssl_verify_mode: ENV['smtp_openssl_verify_mode'] } - - config.log_formatter = RegistryLogFormatter.new # Only works if placed in application.rb end end diff --git a/config/environments/production.rb b/config/environments/production.rb index e0f14e1ea7..0c8989a3bb 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -75,6 +75,9 @@ # Disable automatic flushing of the log to improve performance. # config.autoflush_log = false + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index fb8784c3fe..f2acc88e66 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,6 +1,10 @@ Rails.application.configure do - config.filter_parameters += [:password, :nokogiri_frame, :parsed_frame] + config.filter_parameters += [:password, /^frame$/, /^nokogiri_frame$/, /^parsed_frame$/] config.filter_parameters << lambda do |key, value| - value.to_s.gsub!(/pw>.+<\//, 'pw>[FILTERED].+<\//, 'pw>[FILTERED]]+)>([^<])+<\/eis:legalDocument>/, + "[FILTERED]") + end end end diff --git a/lib/registry_log_formatter.rb b/lib/registry_log_formatter.rb deleted file mode 100644 index 4ce229156d..0000000000 --- a/lib/registry_log_formatter.rb +++ /dev/null @@ -1,13 +0,0 @@ -class RegistryLogFormatter < ::Logger::Formatter - def call(severity, timestamp, progname, msg) - msg = filter_epp_legal_document(msg) - "#{msg}\n" - end - - private - - def filter_epp_legal_document(msg) - msg.gsub(/]+)>([^<])+<\/eis:legalDocument>/, - "[FILTERED]") - end -end