Class: CloseYourIt::Scrubber
- Inherits:
-
Object
- Object
- CloseYourIt::Scrubber
- Defined in:
- lib/closeyourit/scrubber.rb
Overview
Rimozione PII dai payload: filtro chiavi sensibili, normalizzazione SQL, scrub messaggi. Privacy-by-default — vedi PDR §9.
Constant Summary collapse
- FILTERED =
"[FILTERED]"- DENYLIST =
Token di chiavi sempre redatti (match per sottostringa, normalizzato). Allineato 1:1 al regex di backend e client Dart (parità client-side) — vedi Errors/Logs::Ingest::Normalize::SENSITIVE_KEY:
/pass|secret|token|api[_-]?key|apikey|authorization|cookie|csrf|credit|card|cvv|ssn|iban/ipasscopre password/passwd/pass_code/passkey/passphrase;cookiecopre set-cookie;credit+cardcoprono credit_card. La lista letterale precedente ometteva ipass*bare → leak. %w[ pass secret token api_key apikey authorization cookie csrf credit card cvv ssn iban ].freeze
- STRING_LITERAL =
/'(?:[^']|'')*'/- NUMERIC_LITERAL =
/\b\d+(?:\.\d+)?\b/
Instance Method Summary collapse
-
#filter_params(value) ⇒ Object
Filtra ricorsivamente Hash/Array sostituendo i valori delle chiavi sensibili.
-
#filter_value(key, value) ⇒ Object
Valore di un singolo bind/argomento: redatto se il nome (colonna/parametro) è sensibile.
-
#initialize(configuration) ⇒ Scrubber
constructor
A new instance of Scrubber.
-
#obfuscate_sql(sql) ⇒ Object
Maschera i literal (stringa/numerici) nello SQL, preservando la struttura.
- #scrub_message(message) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Scrubber
Returns a new instance of Scrubber.
22 23 24 |
# File 'lib/closeyourit/scrubber.rb', line 22 def initialize(configuration) @configuration = configuration end |
Instance Method Details
#filter_params(value) ⇒ Object
Filtra ricorsivamente Hash/Array sostituendo i valori delle chiavi sensibili.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/closeyourit/scrubber.rb', line 27 def filter_params(value) case value when Hash value.each_with_object({}) do |(key, val), acc| acc[key] = sensitive_key?(key) ? FILTERED : filter_params(val) end when Array value.map { |item| filter_params(item) } else value end end |
#filter_value(key, value) ⇒ Object
Valore di un singolo bind/argomento: redatto se il nome (colonna/parametro) è sensibile.
56 57 58 |
# File 'lib/closeyourit/scrubber.rb', line 56 def filter_value(key, value) sensitive_key?(key) ? FILTERED : value end |
#obfuscate_sql(sql) ⇒ Object
Maschera i literal (stringa/numerici) nello SQL, preservando la struttura.
41 42 43 44 45 |
# File 'lib/closeyourit/scrubber.rb', line 41 def obfuscate_sql(sql) return sql if sql.nil? || !@configuration.obfuscate_sql sql.to_s.gsub(STRING_LITERAL, "?").gsub(NUMERIC_LITERAL, "?") end |
#scrub_message(message) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/closeyourit/scrubber.rb', line 47 def () return if .nil? @configuration..reduce(.to_s) do |acc, pattern| acc.gsub(pattern, FILTERED) end end |