Module: Salopulse::Sanitizer
- Defined in:
- lib/salopulse/sanitizer.rb
Constant Summary collapse
- SENSITIVE_KEYS =
%w[ password password_confirmation token api_key secret access_token refresh_token authorization cookie credit_card card_number cvv ssn ].freeze
- SENSITIVE_HEADERS =
%w[ authorization cookie x-api-key x-auth-token ].freeze
- FILTERED =
"[FILTERED]".freeze
Class Method Summary collapse
Class Method Details
.scrub_hash(value) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/salopulse/sanitizer.rb', line 17 def scrub_hash(value) case value when Hash value.each_with_object({}) do |(k, v), acc| acc[k] = sensitive_key?(k) ? FILTERED : scrub_hash(v) end when Array value.map { |v| scrub_hash(v) } else value end end |
.scrub_headers(headers) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/salopulse/sanitizer.rb', line 30 def scrub_headers(headers) return {} unless headers.respond_to?(:each_pair) || headers.is_a?(Hash) headers.to_h.each_with_object({}) do |(k, v), acc| acc[k] = SENSITIVE_HEADERS.include?(k.to_s.downcase) ? FILTERED : v end end |
.sensitive_key?(key) ⇒ Boolean
37 38 39 |
# File 'lib/salopulse/sanitizer.rb', line 37 def sensitive_key?(key) SENSITIVE_KEYS.include?(key.to_s.downcase) end |