From a8bf62d3a0d34f469c04ec312a494ee8742e2999 Mon Sep 17 00:00:00 2001 From: Yutaka Kamei Date: Mon, 13 Feb 2023 14:34:45 +0900 Subject: [PATCH] Allow partial strings on Rails `filter_parameters` for `meta_data_filters` The Recent Rails template will generate `filter_parameters` with *partial* strings, such as `:passw` and `:_key`. I think this library should also allow such keywords to filter out, following the Rails template. https://github.com/rails/rails/blob/f838a7421228204bbc1e012ff9a3801ed598da80/railties/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt#L6-L8 This patch might be a breaking change because it will filter more parameters than before, but to exclude them would be better than sending probably sensitive parameters as they are. --- .../rails-42/config/initializers/filter_parameter_logging.rb | 2 +- .../rails-51/config/initializers/filter_parameter_logging.rb | 2 +- .../rails-60/config/initializers/filter_parameter_logging.rb | 2 +- .../app/config/initializers/filter_parameter_logging.rb | 2 +- .../rails4/app/config/initializers/filter_parameter_logging.rb | 2 +- .../rails5/app/config/initializers/filter_parameter_logging.rb | 2 +- .../rails6/app/config/initializers/filter_parameter_logging.rb | 2 +- .../rails7/app/config/initializers/filter_parameter_logging.rb | 2 +- .../app/config/initializers/filter_parameter_logging.rb | 2 +- lib/bugsnag/integrations/railtie.rb | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/example/rails-42/config/initializers/filter_parameter_logging.rb b/example/rails-42/config/initializers/filter_parameter_logging.rb index 4a994e1e7..48aaef212 100644 --- a/example/rails-42/config/initializers/filter_parameter_logging.rb +++ b/example/rails-42/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,4 @@ # 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 += [:passw] diff --git a/example/rails-51/config/initializers/filter_parameter_logging.rb b/example/rails-51/config/initializers/filter_parameter_logging.rb index 4a994e1e7..48aaef212 100644 --- a/example/rails-51/config/initializers/filter_parameter_logging.rb +++ b/example/rails-51/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,4 @@ # 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 += [:passw] diff --git a/example/rails-60/config/initializers/filter_parameter_logging.rb b/example/rails-60/config/initializers/filter_parameter_logging.rb index 4a994e1e7..48aaef212 100644 --- a/example/rails-60/config/initializers/filter_parameter_logging.rb +++ b/example/rails-60/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,4 @@ # 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 += [:passw] diff --git a/features/fixtures/delayed_job/app/config/initializers/filter_parameter_logging.rb b/features/fixtures/delayed_job/app/config/initializers/filter_parameter_logging.rb index 4a994e1e7..48aaef212 100644 --- a/features/fixtures/delayed_job/app/config/initializers/filter_parameter_logging.rb +++ b/features/fixtures/delayed_job/app/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,4 @@ # 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 += [:passw] diff --git a/features/fixtures/rails4/app/config/initializers/filter_parameter_logging.rb b/features/fixtures/rails4/app/config/initializers/filter_parameter_logging.rb index 932e66b17..701c53475 100644 --- a/features/fixtures/rails4/app/config/initializers/filter_parameter_logging.rb +++ b/features/fixtures/rails4/app/config/initializers/filter_parameter_logging.rb @@ -1,5 +1,5 @@ # 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 += [:passw] Rails.application.config.filter_parameters += [:my_specific_filter] diff --git a/features/fixtures/rails5/app/config/initializers/filter_parameter_logging.rb b/features/fixtures/rails5/app/config/initializers/filter_parameter_logging.rb index 932e66b17..701c53475 100644 --- a/features/fixtures/rails5/app/config/initializers/filter_parameter_logging.rb +++ b/features/fixtures/rails5/app/config/initializers/filter_parameter_logging.rb @@ -1,5 +1,5 @@ # 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 += [:passw] Rails.application.config.filter_parameters += [:my_specific_filter] diff --git a/features/fixtures/rails6/app/config/initializers/filter_parameter_logging.rb b/features/fixtures/rails6/app/config/initializers/filter_parameter_logging.rb index 932e66b17..701c53475 100644 --- a/features/fixtures/rails6/app/config/initializers/filter_parameter_logging.rb +++ b/features/fixtures/rails6/app/config/initializers/filter_parameter_logging.rb @@ -1,5 +1,5 @@ # 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 += [:passw] Rails.application.config.filter_parameters += [:my_specific_filter] diff --git a/features/fixtures/rails7/app/config/initializers/filter_parameter_logging.rb b/features/fixtures/rails7/app/config/initializers/filter_parameter_logging.rb index 932e66b17..701c53475 100644 --- a/features/fixtures/rails7/app/config/initializers/filter_parameter_logging.rb +++ b/features/fixtures/rails7/app/config/initializers/filter_parameter_logging.rb @@ -1,5 +1,5 @@ # 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 += [:passw] Rails.application.config.filter_parameters += [:my_specific_filter] diff --git a/features/fixtures/rails_integrations/app/config/initializers/filter_parameter_logging.rb b/features/fixtures/rails_integrations/app/config/initializers/filter_parameter_logging.rb index 4a994e1e7..48aaef212 100644 --- a/features/fixtures/rails_integrations/app/config/initializers/filter_parameter_logging.rb +++ b/features/fixtures/rails_integrations/app/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,4 @@ # 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 += [:passw] diff --git a/lib/bugsnag/integrations/railtie.rb b/lib/bugsnag/integrations/railtie.rb index 590e16a20..d5c83826c 100644 --- a/lib/bugsnag/integrations/railtie.rb +++ b/lib/bugsnag/integrations/railtie.rb @@ -121,7 +121,7 @@ def self.rescue_in_active_record_callbacks? config.meta_data_filters += ::Rails.configuration.filter_parameters.map do |filter| case filter when String, Symbol - /\A#{filter}\z/ + /#{filter}/i else filter end