Class: Hoss::Transport::Filters::HashSanitizer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hoss/transport/filters/hash_sanitizer.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

FILTERED =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'[FILTERED]'
KEY_FILTERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[
  /passw(or)?d/i,
  /auth/i,
  /^pw$/,
  /secret/i,
  /token/i,
  /api[-._]?key/i,
  /session[-._]?id/i,
  /(set[-_])?cookie/i
].freeze
VALUE_FILTERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[
  # (probably) credit card number
  /^\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}$/
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHashSanitizer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HashSanitizer.



44
45
46
# File 'lib/hoss/transport/filters/hash_sanitizer.rb', line 44

def initialize
  @key_filters = KEY_FILTERS
end

Instance Attribute Details

#key_filtersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
# File 'lib/hoss/transport/filters/hash_sanitizer.rb', line 42

def key_filters
  @key_filters
end

Instance Method Details

#filter_key?(key) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


67
68
69
# File 'lib/hoss/transport/filters/hash_sanitizer.rb', line 67

def filter_key?(key)
  @key_filters.any? { |regex| regex.match(key) }
end

#filter_value?(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


71
72
73
# File 'lib/hoss/transport/filters/hash_sanitizer.rb', line 71

def filter_value?(value)
  VALUE_FILTERS.any? { |regex| regex.match(value) }
end

#strip_from!(obj, key_filters = KEY_FILTERS) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hoss/transport/filters/hash_sanitizer.rb', line 48

def strip_from!(obj, key_filters = KEY_FILTERS)
  return unless obj&.is_a?(Hash)

  obj.each do |k, v|
    if filter_key?(k)
      next obj[k] = FILTERED
    end

    case v
    when Hash
      strip_from!(v)
    when String
      if filter_value?(v)
        obj[k] = FILTERED
      end
    end
  end
end