Class: CloseYourIt::Scrubber

Inherits:
Object
  • Object
show all
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/i

pass copre password/passwd/pass_code/passkey/passphrase; cookie copre set-cookie; credit+card coprono credit_card. La lista letterale precedente ometteva i pass* 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

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 scrub_message(message)
  return message if message.nil?

  @configuration.scrub_message_patterns.reduce(message.to_s) do |acc, pattern|
    acc.gsub(pattern, FILTERED)
  end
end