Skip to content

Commit

Permalink
Deep clone options, fixes #4499
Browse files Browse the repository at this point in the history
Ensures any password mangling doesn't affect the runtime options
  • Loading branch information
mperham committed Apr 1, 2020
1 parent 432f95f commit 3f9c4bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changes.md
Expand Up @@ -8,6 +8,7 @@ HEAD
- Refactor systemd integration to work better with custom binaries [#4511]
- Don't connect to Redis at process exit if not needed [#4502]
- Remove Redis connection naming [#4479]
- Fix Redis Sentinel password redaction [#4499]

6.0.6
---------
Expand Down
5 changes: 3 additions & 2 deletions lib/sidekiq/redis_connection.rb
Expand Up @@ -94,9 +94,10 @@ def client_opts(options)
end

def log_info(options)
# Don't log Redis AUTH password
redacted = "REDACTED"
scrubbed_options = options.dup

# deep clone so we can muck with these options all we want
scrubbed_options = Marshal.load(Marshal.dump(options))
if scrubbed_options[:url] && (uri = URI.parse(scrubbed_options[:url])) && uri.password
uri.password = redacted
scrubbed_options[:url] = uri.to_s
Expand Down
23 changes: 13 additions & 10 deletions test/test_redis_connection.rb
Expand Up @@ -190,19 +190,22 @@ def server_connection(*args)

describe 'logging redis options' do
it 'redacts credentials' do
options = {
role: 'master',
master_name: 'mymaster',
sentinels: [
{ host: 'host1', port: 26379, password: 'secret'},
{ host: 'host2', port: 26379, password: 'secret'},
{ host: 'host3', port: 26379, password: 'secret'},
],
password: 'secret'
}

output = capture_logging do
Sidekiq::RedisConnection.create(
role: 'master',
master_name: 'mymaster',
sentinels: [
{ host: 'host1', port: 26379, password: 'secret'},
{ host: 'host2', port: 26379, password: 'secret'},
{ host: 'host3', port: 26379, password: 'secret'},
],
password: 'secret'
)
Sidekiq::RedisConnection.create(options)
end

refute_includes(options.inspect, "REDACTED")
assert_includes(output, ':host=>"host1", :port=>26379, :password=>"REDACTED"')
assert_includes(output, ':host=>"host2", :port=>26379, :password=>"REDACTED"')
assert_includes(output, ':host=>"host3", :port=>26379, :password=>"REDACTED"')
Expand Down

0 comments on commit 3f9c4bf

Please sign in to comment.