Class: Sentry::DataCollection::KeyValueCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/data_collection/key_value_collection.rb

Overview

Configuration for key-value data collection.

Constant Summary collapse

FILTERED_VALUE =
"[Filtered]"
SENSITIVE_DENY_LIST =

Keys from this list are ALWAYS filtered, regardless of :mode

%w[
  auth
  token
  secret
  session
  password
  passwd
  pwd
  key
  jwt
  bearer
  sso
  saml
  csrf
  xsrf
  credentials
  sid
  identity
  cookie
  set-cookie
].freeze
%w[
  .sid
  sessid
  remember
  oidc
  pkce
  nonce
  __secure-
  __host-
  awsalb
  awselb
  akamai
  __stripe
  cognito
  firebase
  supabase
  sb-
  mfa
  2fa
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode:, terms:) ⇒ KeyValueCollection

Returns a new instance of KeyValueCollection.



68
69
70
71
# File 'lib/sentry/data_collection/key_value_collection.rb', line 68

def initialize(mode:, terms:)
  self.mode = mode
  self.terms = terms
end

Instance Attribute Details

#mode:off, ...

mode controls whether values are collected:

  • :off disables collection.
  • :deny_list collects values except those matching terms.
  • :allow_list collects only values matching terms. Boolean values are accepted as shorthand for :deny_list and :off.

Returns:

  • (:off, :deny_list, :allow_list)


62
63
64
# File 'lib/sentry/data_collection/key_value_collection.rb', line 62

def mode
  @mode
end

#termsArray<String, Regexp>?

terms contains the keys or patterns used by the selected mode.

Returns:

  • (Array<String, Regexp>, nil)


66
67
68
# File 'lib/sentry/data_collection/key_value_collection.rb', line 66

def terms
  @terms
end

Class Method Details

.from(value) ⇒ Object

Converts the boolean shorthand into a collection configuration.



82
83
84
85
86
# File 'lib/sentry/data_collection/key_value_collection.rb', line 82

def self.from(value)
  return new(mode: value, terms: nil) if value.equal?(true) || value.equal?(false) || value.nil?

  value
end

Instance Method Details

#filter(values, cookie: false) ⇒ Hash

Applies this collection configuration without changing the input hash. Keys are retained whenever the category is collected; values that are not safe to send are replaced with FILTERED_VALUE.

Parameters:

  • values (Hash)

    key-value data to filter

Returns:

  • (Hash)

    a new filtered hash, or an empty hash when collection is off



99
100
101
102
103
104
105
# File 'lib/sentry/data_collection/key_value_collection.rb', line 99

def filter(values, cookie: false)
  return {} if mode == :off

  values.each_with_object({}) do |(key, value), filtered|
    filtered[key] = safe_value?(key, cookie: cookie) ? value : FILTERED_VALUE
  end
end