class LittleGhost::Support::Redactor
Redactor removes common credential keys, known secret values, and secret-shaped strings from nested diagnostic data. It returns a copy and leaves the caller’s value unchanged.
Redaction is a defense-in-depth aid, not proof that arbitrary sensitive content is safe to export. Applications should add known secret values and keep telemetry within an appropriate trust boundary.
Public Class Methods
# File lib/little_ghost/support/redactor.rb, line 23 def initialize(redactions: [], stringify_keys: false) @redactions = Array(redactions).map(&:to_s).reject { |value| value.length < 8 }.uniq.freeze @stringify_keys = stringify_keys end
Adds literal secrets to the built-in patterns. Values shorter than eight characters are ignored to avoid over-redaction.
Public Instance Methods
Source
# File lib/little_ghost/support/redactor.rb, line 29 def call(value, key: nil) return "[REDACTED]" if key && sensitive_key?(key) case value when Hash value.to_h do |child_key, child| output_key = @stringify_keys ? child_key.to_s : child_key [output_key, call(child, key: child_key)] end when Array value.map { |child| call(child) } when String scrub_string(value) else value end end
Produces a redacted copy of value.
Source
# File lib/little_ghost/support/redactor.rb, line 53 def scrub_string(value) normalized = value.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "\uFFFD") text = @redactions.reduce(normalized) { |current, secret| current.gsub(secret, "[REDACTED]") } SECRET_PATTERNS.reduce(text) { |current, pattern| current.gsub(pattern, "[REDACTED]") } end
Normalizes invalid UTF-8 and replaces configured and common secrets.
Source
# File lib/little_ghost/support/redactor.rb, line 48 def sensitive_key?(key) SENSITIVE_KEY.match?(normalize_key(key)) end
Checks whether key matches a credential-like name.