Skip to content

Commit 862a0ff

Browse files
fix(redis): Do not record credentials from AUTH and admin commands (#3189)
* fix(redis): Do not record AUTH and HELLO arguments The Redis formatter always recorded the second command element as the key, so AUTH <password> put the password into span descriptions and breadcrumbs regardless of data collection settings. HELLO's AUTH arguments were recorded whenever database query data collection was enabled. Record only the command name for these commands. Resolves SDK-1226 Co-Authored-By: Johannes Daxböck <114897+dingsdax@users.noreply.github.com> * fix(redis): Do not record arguments of admin commands With database query data collection enabled, admin commands recorded all arguments, including credentials from CONFIG SET requirepass, ACL SETUSER, MIGRATE ... AUTH and SENTINEL SET ... auth-pass. Record only the command and subcommand for ACL, CONFIG, MIGRATE and SENTINEL. Refs SDK-1226 Co-Authored-By: Johannes Daxböck <114897+dingsdax@users.noreply.github.com> * fix comments --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Johannes Daxböck <114897+dingsdax@users.noreply.github.com> Co-authored-by: Johannes Daxböck <johannes.daxboeck@sentry.io>
1 parent a62cf84 commit 862a0ff

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎sentry-ruby/lib/sentry/redis.rb‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ class Redis
66
OP_NAME = "db.redis"
77
SPAN_ORIGIN = "auto.db.redis"
88
LOGGER_NAME = :redis_logger
9+
# Commands that carry credentials from their first argument on.
10+
SENSITIVE_COMMANDS = %w[AUTH HELLO].freeze
11+
# Commands whose later arguments can carry credentials. Arguments are never recorded.
12+
ARGUMENTLESS_COMMANDS = %w[ACL CONFIG MIGRATE SENTINEL].freeze
913

1014
def initialize(commands, host, port, db)
1115
@commands, @host, @port, @db = commands, host, port, db
@@ -60,9 +64,11 @@ def parsed_commands
6064
commands.map do |statement|
6165
command, key, *arguments = statement
6266
command_set = { command: command.to_s.upcase }
67+
next command_set if SENSITIVE_COMMANDS.include?(command_set[:command])
68+
6369
command_set[:key] = key if Utils::EncodingHelper.valid_utf_8?(key)
6470

65-
if Sentry.configuration.data_collection.database_query_data
71+
if Sentry.configuration.data_collection.database_query_data && !ARGUMENTLESS_COMMANDS.include?(command_set[:command])
6672
command_set[:arguments] = arguments
6773
.select { |a| Utils::EncodingHelper.valid_utf_8?(a) }
6874
.join(" ")

‎sentry-ruby/spec/sentry/redis_spec.rb‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,41 @@
3232
end
3333
end
3434

35+
describe "credentials" do
36+
before do
37+
Sentry.configuration.data_collection.database_query_data = true
38+
Sentry.configuration.breadcrumbs_logger = [:redis_logger]
39+
end
40+
41+
# The test Redis has no password, so the default user accepts any password.
42+
[
43+
["AUTH", "default", "secret"],
44+
["HELLO", "2", "AUTH", "default", "secret"]
45+
].each do |command|
46+
it "does not record #{command.first} arguments" do
47+
transaction = Sentry.start_transaction
48+
Sentry.get_current_scope.set_span(transaction)
49+
50+
redis.call(*command)
51+
52+
expect(transaction.span_recorder.spans.last.description).to eq(command.first)
53+
expect(Sentry.get_current_scope.breadcrumbs.peek.data[:commands]).to eq([{ command: command.first }])
54+
end
55+
end
56+
57+
it "does not record arguments of admin commands" do
58+
transaction = Sentry.start_transaction
59+
Sentry.get_current_scope.set_span(transaction)
60+
61+
redis.call("ACL", "SETUSER", "sentry-test-user", ">secret")
62+
63+
expect(transaction.span_recorder.spans.last.description).to eq("ACL SETUSER")
64+
expect(Sentry.get_current_scope.breadcrumbs.peek.data[:commands]).to eq([{ command: "ACL", key: "SETUSER" }])
65+
ensure
66+
redis.call("ACL", "DELUSER", "sentry-test-user")
67+
end
68+
end
69+
3570
context "config.send_default_pii = true" do
3671
before { Sentry.configuration.send_default_pii = true }
3772

0 commit comments

Comments
 (0)