Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions filtering for nested params #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/padrino-contrib/exception_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ def self.registered(app)
env.each { |k,v| body += "\n#{k}: #{v}" }
body += "\n\n---Params:\n"
params.each do |k,v|
if settings.exceptions_params_filter.include?(k)
body += "\n#{k.inspect} => [FILTERED]"
if v.is_a? Hash
(settings.exceptions_params_filter & v.keys).each{ |key| v.merge! key => '[FILTERED]' }
body += "\n#{k.inspect} => { #{v.map{ |k,v| "#{k.inspect} => #{v == '[FILTERED]' ? v.chomp : v.inspect}" }.join(', ')} }"
else
body += "\n#{k.inspect} => #{v.inspect}"
if settings.exceptions_params_filter.include?(k)
body += "\n#{k.inspect} => [FILTERED]"
else
body += "\n#{k.inspect} => #{v.inspect}"
end
end
end
logger.error body
Expand Down
9 changes: 9 additions & 0 deletions spec/exception_notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ def last_email
expect(last_email.body).to match /"foo" => \[FILTERED\]/
end

it 'allows filtering of nested request params' do
get '/boom', { :account => { :email => '[email protected]',
:password => 'super_secret',
:password_confirmation => 'super_secret' }
}
expect(last_email.body).to match /"password" => \[FILTERED\]/
expect(last_email.body).to match /"password_confirmation" => \[FILTERED\]/
end

it 'renders an error page' do
get '/boom'
expect(last_response.status).to eq 500
Expand Down