Module: Dadata::SensitiveData
- Included in:
- ClientBase, Configuration, SecureLogger, SensitiveDataMiddleware
- Defined in:
- lib/dadata/sensitive_data.rb
Overview
The SensitiveData module provides functionality for sanitizing sensitive information in log messages and HTTP headers. It is used internally by the gem to ensure that sensitive data such as API keys and secrets are not exposed in logs.
Constant Summary collapse
- SENSITIVE_HEADERS =
List of headers that contain sensitive information and should be filtered
%w[Authorization X-Secret API-Key].freeze
Instance Method Summary collapse
-
#sanitize_headers(headers) ⇒ String
Sanitizes headers by replacing sensitive values with [FILTERED].
-
#sanitize_message(msg) ⇒ String
Sanitizes a message by replacing sensitive information with [FILTERED].
Instance Method Details
#sanitize_headers(headers) ⇒ String
Sanitizes headers by replacing sensitive values with [FILTERED]
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dadata/sensitive_data.rb', line 27 def sanitize_headers(headers) return '' unless headers headers.map do |key, value| if SENSITIVE_HEADERS.include?(key) "#{key}: [FILTERED]" else "#{key}: #{value}" end end.join(', ') end |
#sanitize_message(msg) ⇒ String
Sanitizes a message by replacing sensitive information with [FILTERED]
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dadata/sensitive_data.rb', line 46 def (msg) return '' unless msg.is_a?(String) result = msg.dup SENSITIVE_HEADERS.each do |header| # Escape hyphens in the header name and handle any whitespace around the colon pattern = /#{Regexp.escape(header)}[\s]*:[\s]*[^\n,]+/ result = result.gsub(pattern, "#{header}: [FILTERED]") end result end |