From 3ddc8555e64487cc207ebffab8bfb1e64807c8d4 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2026 12:21:26 +0000 Subject: [PATCH] fix(redis): Record arguments only for allowlisted commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With database query data collection enabled, every command recorded its arguments, including admin commands that carry credentials such as CONFIG SET requirepass, ACL SETUSER and MIGRATE ... AUTH. Record arguments only for commands on the allowlist from OpenTelemetry's redis-common serializer, which sentry-javascript also uses. Other commands record their command name and key. Refs SDK-1226 Co-Authored-By: Johannes Daxböck <114897+dingsdax@users.noreply.github.com> --- sentry-ruby/lib/sentry/redis.rb | 6 +++++- sentry-ruby/spec/sentry/redis_spec.rb | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sentry-ruby/lib/sentry/redis.rb b/sentry-ruby/lib/sentry/redis.rb index f537762c8..44e1cedfa 100644 --- a/sentry-ruby/lib/sentry/redis.rb +++ b/sentry-ruby/lib/sentry/redis.rb @@ -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 @@ -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(" ") diff --git a/sentry-ruby/spec/sentry/redis_spec.rb b/sentry-ruby/spec/sentry/redis_spec.rb index faad3aeea..aaef7d7d2 100644 --- a/sentry-ruby/spec/sentry/redis_spec.rb +++ b/sentry-ruby/spec/sentry/redis_spec.rb @@ -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