Skip to content

Commit

Permalink
filters: make it possible to filter out user
Browse files Browse the repository at this point in the history
A user reported that it's not possible to filter context/user. It's a
reasonable request given that the user information has been moved to
context recently.

Here we special-case context/user because we do want to be able to
filter it, but we don't want to filter out other payload in `context`.
  • Loading branch information
kyrylo committed Mar 3, 2016
1 parent fa9023e commit 7ee08db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions lib/airbrake-ruby/filters/keys_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module Filters
# @see KeysWhitelist
# @see KeysBlacklist
module KeysFilter
FILTERED = '[Filtered]'.freeze

##
# Creates a new KeysBlacklist or KeysWhitelist filter that uses the given
# +patterns+ for filtering a notice's payload.
Expand All @@ -28,6 +30,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?
Expand Down
11 changes: 11 additions & 0 deletions spec/notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ee08db

Please sign in to comment.