Class: Raven::Processor::SanitizeData

Inherits:
Raven::Processor show all
Defined in:
lib/raven/processor/sanitizedata.rb

Constant Summary collapse

DEFAULT_FIELDS =
%w(authorization password passwd secret ssn social(.*)?sec).freeze
CREDIT_CARD_RE =
/\b(?:3[47]\d|(?:4\d|5[1-5]|65)\d{2}|6011)\d{12}\b/
QUERY_STRING =
['query_string', :query_string].freeze
JSON_STARTS_WITH =
["[", "{"].freeze

Constants inherited from Raven::Processor

INT_MASK, REGEX_SPECIAL_CHARACTERS, STRING_MASK

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ SanitizeData


13
14
15
16
17
18
# File 'lib/raven/processor/sanitizedata.rb', line 13

def initialize(client)
  super
  self.sanitize_fields = client.configuration.sanitize_fields
  self.sanitize_credit_cards = client.configuration.sanitize_credit_cards
  self.sanitize_fields_excluded = client.configuration.sanitize_fields_excluded
end

Instance Attribute Details

#sanitize_credit_cardsObject

Returns the value of attribute sanitize_credit_cards


11
12
13
# File 'lib/raven/processor/sanitizedata.rb', line 11

def sanitize_credit_cards
  @sanitize_credit_cards
end

#sanitize_fieldsObject

Returns the value of attribute sanitize_fields


11
12
13
# File 'lib/raven/processor/sanitizedata.rb', line 11

def sanitize_fields
  @sanitize_fields
end

#sanitize_fields_excludedObject

Returns the value of attribute sanitize_fields_excluded


11
12
13
# File 'lib/raven/processor/sanitizedata.rb', line 11

def sanitize_fields_excluded
  @sanitize_fields_excluded
end

Instance Method Details

#process(value, key = nil) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/raven/processor/sanitizedata.rb', line 20

def process(value, key = nil)
  case value
  when Hash
    !value.frozen? ? value.merge!(value) { |k, v| process v, k } : value.merge(value) { |k, v| process v, k }
  when Array
    !value.frozen? ? value.map! { |v| process v, key } : value.map { |v| process v, key }
  when Integer
    matches_regexes?(key, value.to_s) ? INT_MASK : value
  when String
    if value =~ fields_re && (json = parse_json_or_nil(value))
      # if this string is actually a json obj, convert and sanitize
      process(json).to_json
    elsif matches_regexes?(key, value)
      STRING_MASK
    elsif QUERY_STRING.include?(key)
      sanitize_query_string(value)
    else
      value
    end
  else
    value
  end
end