-
-
Save millisami/1330193 to your computer and use it in GitHub Desktop.
Removing sensitive resque args from airbrake notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Resque::Failure::SensitiveAirbrake.configure do |config| | |
config.api_key = @config['airbrake']['api_key'] | |
config.params_filters << 'my_sensitive_job_arg' | |
config.secure = @config['airbrake']['secure'] | |
config.proxy_host = @config['airbrake']['proxy_host'] | |
config.proxy_port = @config['airbrake']['proxy_port'] | |
config.host = @config['airbrake']['host'] | |
config.logger = Logger.new(STDOUT) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'resque/failure' | |
require 'resque/failure/base' | |
require 'resque/failure/airbrake' | |
module Resque | |
module Failure | |
class SensitiveAirbrake < Airbrake | |
@klass = ::Airbrake | |
def payload | |
args = super['args'].first.dup | |
::Airbrake.configuration.params_filters.each do |filtered_param| | |
args[filtered_param] = '[SENSITIVE-FILTERED]' if args[filtered_param] | |
end | |
super.dup.merge('args' => [args]) | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/../test_helper' | |
require 'sensitive_airbrake' | |
describe Resque::Failure::SensitiveAirbrake do | |
before(:each) do | |
@worker = mock('worker') | |
@exception = Exception.new('something bad occurred') | |
@exception.set_backtrace [] | |
@queue = 'some-queue' | |
@payload = {} | |
@payload['class'] = 'SomeJob' | |
@payload['args'] = [{ 'sensitive' => 'this is sensitive information', 'safe' => 'this is safe information' }] | |
end | |
it 'should keep all the payload_args by default' do | |
payload = Resque::Failure::SensitiveAirbrake.new(@exception, @worker, @queue, @payload).payload.inspect | |
payload.should include 'sensitive information' | |
payload.should include 'safe information' | |
end | |
it 'should NOT keep sensitive information from the payload_args' do | |
Resque::Failure::SensitiveAirbrake.configure do |config| | |
config.params_filters << 'sensitive' | |
end | |
payload = Resque::Failure::SensitiveAirbrake.new(@exception, @worker, @queue, @payload).payload.inspect | |
payload.should_not include 'sensitive information' | |
payload.should include 'safe information' | |
end | |
it 'should not add password (default params filters)' do | |
Resque::Failure::SensitiveAirbrake.configure do |config| | |
config.params_filters << 'sensitive' | |
end | |
payload = Resque::Failure::SensitiveAirbrake.new(@exception, @worker, @queue, @payload).payload.inspect | |
payload.should_not include 'password' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment