Skip to content
Closed
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
6 changes: 5 additions & 1 deletion sentry-ruby/lib/sentry/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class Redis
LOGGER_NAME = :redis_logger
# Commands whose arguments carry credentials and must never be recorded.
SENSITIVE_COMMANDS = %w[AUTH HELLO].freeze
# Commands whose arguments may be recorded when database query data collection is enabled.
# The command prefixes come from OpenTelemetry's redis-common serializer, which sentry-javascript uses.
# Other commands, such as CONFIG SET, ACL SETUSER and MIGRATE, can carry credentials and only record their key.
ARGUMENTS_ALLOWLIST = /\A(?:GETSET|LPUSH|MSET|PFA|PSETEX|PUBLISH|RPUSH|SADD|SET|SPUBLISH|XADD|ZADD|HSET|HMSET|LSET|LINSERT|BIT|B[LRZ]|CLIENT|CLUSTER|COMMAND|DECR|DEL|EVAL|EX|FUNCTION|GEO|GET|HINCR|HMGET|HSCAN|INCR|L[TRLM]|MEMORY|P[EFISTU]|RPOP|S[CDIMORSU]|XACK|X[CDGILPRT]|Z[CDILMPRS])/

def initialize(commands, host, port, db)
@commands, @host, @port, @db = commands, host, port, db
Expand Down Expand Up @@ -66,7 +70,7 @@ def parsed_commands

command_set[:key] = key if Utils::EncodingHelper.valid_utf_8?(key)

if Sentry.configuration.data_collection.database_query_data
if Sentry.configuration.data_collection.database_query_data && ARGUMENTS_ALLOWLIST.match?(command_set[:command])
command_set[:arguments] = arguments
.select { |a| Utils::EncodingHelper.valid_utf_8?(a) }
.join(" ")
Expand Down
10 changes: 10 additions & 0 deletions sentry-ruby/spec/sentry/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
expect(Sentry.get_current_scope.breadcrumbs.peek.data[:commands]).to eq([{ command: command.first }])
end
end

it "records only the subcommand of commands that are not allowlisted" do
transaction = Sentry.start_transaction
Sentry.get_current_scope.set_span(transaction)

redis.call("CONFIG", "GET", "maxmemory")

expect(transaction.span_recorder.spans.last.description).to eq("CONFIG GET")
expect(Sentry.get_current_scope.breadcrumbs.peek.data[:commands]).to eq([{ command: "CONFIG", key: "GET" }])
end
end

context "config.send_default_pii = true" do
Expand Down
Loading