Skip to content

Commit

Permalink
Scrub all arguments when an ActiveJob is configured not to log argume…
Browse files Browse the repository at this point in the history
…nts (#1059)

Rails 6.1.0 introduced an option for disabling logging of job arguments
in ActiveJob[1][2]. This change makes the ActiveJob plugin aware of this
config option and scrubs all arguments if we're dealing with a sensitive
job.

[1]: https://github.com/rails/rails/releases/tag/v6.1.0
[2]: rails/rails#37660
  • Loading branch information
Be-ngt-oH committed Jul 8, 2021
1 parent c1a2a00 commit b0cf1da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rollbar/plugins/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ module Rollbar
module ActiveJob
def self.included(base)
base.send :rescue_from, Exception do |exception|
args = if self.class.respond_to?(:log_arguments?) && !self.class.log_arguments?
arguments.map(&Rollbar::Scrubbers.method(:scrub_value))
else
arguments
end

Rollbar.error(exception,
:job => self.class.name,
:job_id => job_id,
:use_exception_level_filters => true,
:arguments => arguments)
:arguments => args)
raise exception
end
end
Expand Down
17 changes: 17 additions & 0 deletions spec/rollbar/plugins/active_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ def perform(exception, job_id)
end.to raise_error exception
end

it 'scrubs all arguments if job has `log_arguments` disabled' do
allow(TestJob).to receive(:log_arguments?).and_return(false)

expected_params = {
:job => 'TestJob',
:job_id => job_id,
:use_exception_level_filters => true,
:arguments => ['******', '******', '******']
}
expect(Rollbar).to receive(:error).with(exception, expected_params)
begin
TestJob.new(1, 2, 3).perform(exception, job_id)
rescue StandardError
nil
end
end

context 'using ActionMailer::DeliveryJob', :if => defined?(ActionMailer::DeliveryJob) do
include ActiveJob::TestHelper if defined?(ActiveJob::TestHelper)

Expand Down

0 comments on commit b0cf1da

Please sign in to comment.