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 =
/^(?:\d[ -]*?){13,16}$/

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

Returns a new instance of SanitizeData.



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

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

Instance Attribute Details

#sanitize_credit_cardsObject

Returns the value of attribute sanitize_credit_cards.



9
10
11
# File 'lib/raven/processor/sanitizedata.rb', line 9

def sanitize_credit_cards
  @sanitize_credit_cards
end

#sanitize_fieldsObject

Returns the value of attribute sanitize_fields.



9
10
11
# File 'lib/raven/processor/sanitizedata.rb', line 9

def sanitize_fields
  @sanitize_fields
end

Instance Method Details

#process(value) ⇒ Object



17
18
19
20
# File 'lib/raven/processor/sanitizedata.rb', line 17

def process(value)
  return value if value.frozen?
  value.each_with_object(value) { |(k, v), memo| memo[k] = sanitize(k, v) }
end

#sanitize(k, v) ⇒ Object



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

def sanitize(k, v)
  if v.is_a?(Hash)
    process(v)
  elsif v.is_a?(Array)
    v.map { |a| sanitize(k, a) }
  elsif k.to_s == 'query_string'
    sanitize_query_string(v)
  elsif v.is_a?(Integer) && matches_regexes?(k, v)
    INT_MASK
  elsif v.is_a?(String)
    if fields_re.match(v.to_s) && (json = parse_json_or_nil(v))
      # if this string is actually a json obj, convert and sanitize
      json.is_a?(Hash) ? process(json).to_json : v
    elsif matches_regexes?(k, v)
      STRING_MASK
    else
      v
    end
  else
    v
  end
end