Class: Lennarb::ParameterFilter
- Inherits:
-
Object
- Object
- Lennarb::ParameterFilter
- Defined in:
- lib/lennarb/parameter_filter.rb
Overview
Filters sensitive parameters from logs and exceptions. Useful for preventing the leakage of confidential information.
By default, the following parameter keys are filtered:
passwemailsecrettoken_keycryptsaltcertificateotpssncvvcvcsignatureauthcreditcard_numbercvnibanapipinsession_id
Matching is case-insensitive, so Password and API_KEY are filtered too.
Constant Summary collapse
- DEFAULT_MASK =
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]"- DEFAULT_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.
%w[ passw email secret token _key crypt salt certificate otp ssn cvv cvc signature auth credit card_number cvn iban api pin session_id ].freeze
Instance Method Summary collapse
-
#filter(params, mask: DEFAULT_MASK) ⇒ Hash, Array
Filter parameters according to the configured filter.
-
#initialize(filters = DEFAULT_FILTERS) ⇒ ParameterFilter
constructor
Initialize a new parameter filter.
Constructor Details
#initialize(filters = DEFAULT_FILTERS) ⇒ ParameterFilter
Initialize a new parameter filter
Regexp filters are used as given. Anything else is matched as a literal substring of the key, case-insensitively.
52 53 54 55 |
# File 'lib/lennarb/parameter_filter.rb', line 52 def initialize(filters = DEFAULT_FILTERS) union = Regexp.union(filters.map { |pattern| pattern.is_a?(Regexp) ? pattern : pattern.to_s }) @filter = Regexp.new(union.source, Regexp::IGNORECASE) end |
Instance Method Details
#filter(params, mask: DEFAULT_MASK) ⇒ Hash, Array
Filter parameters according to the configured filter
62 63 64 |
# File 'lib/lennarb/parameter_filter.rb', line 62 def filter(params, mask: DEFAULT_MASK) filter_object(params, mask) end |