diff --git a/CHANGELOG.md b/CHANGELOG.md index 45c14ff5..f4ac2a8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ Airbrake Ruby Changelog ### master +* Started filtering the context payload + ([#55](https://github.com/airbrake/airbrake-ruby/pull/55)) * Fixed bug when similar keys would be filtered out using non-regexp values for `Airbrake.blacklist/whitelist_keys` ([#54](https://github.com/airbrake/airbrake-ruby/pull/54)) diff --git a/lib/airbrake-ruby/filters/keys_filter.rb b/lib/airbrake-ruby/filters/keys_filter.rb index ed47646b..d52fb889 100644 --- a/lib/airbrake-ruby/filters/keys_filter.rb +++ b/lib/airbrake-ruby/filters/keys_filter.rb @@ -9,6 +9,10 @@ module Filters # @see KeysWhitelist # @see KeysBlacklist module KeysFilter + ## + # @return [String] The label to replace real values of filtered payload + FILTERED = '[Filtered]'.freeze + ## # Creates a new KeysBlacklist or KeysWhitelist filter that uses the given # +patterns+ for filtering a notice's payload. @@ -28,6 +32,10 @@ def initialize(*patterns) def call(notice) FILTERABLE_KEYS.each { |key| filter_hash(notice[key]) } + if notice[:context][:user] && should_filter?(:user) + notice[:context][:user] = FILTERED + end + return unless notice[:context][:url] url = URI(notice[:context][:url]) return if url.nil? || url.query.nil? diff --git a/spec/notifier_spec.rb b/spec/notifier_spec.rb index f29894ed..eee40675 100644 --- a/spec/notifier_spec.rb +++ b/spec/notifier_spec.rb @@ -553,6 +553,17 @@ def to_json(*) with(body: expected_body) ).to have_been_made.once end + + it "filters out user" do + @airbrake.blacklist_keys('user') + + notice = @airbrake.build_notice(ex) + notice[:context][:user] = { id: 1337, name: 'Bingo Bango' } + + @airbrake.notify_sync(notice) + + expect_a_request_with_body(/"user":"\[Filtered\]"/) + end end describe "#whitelist_keys" do