Module: Sqreen::Legacy::WafRedactions

Defined in:
lib/sqreen/legacy/waf_redactions.rb

Class Method Summary collapse

Class Method Details

.redact_attacks!(attacks, values) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sqreen/legacy/waf_redactions.rb', line 10

def redact_attacks!(attacks, values)
  return attacks if values.empty?

  values = values.map { |v| v.downcase if v.is_a?(String) }

  attacks.each do |e|
    next(e) unless e[:infos]
    next(e) unless e[:infos][:waf_data]

    parsed = JSON.parse(e[:infos][:waf_data])
    redacted = parsed.each do |w|
      next unless (filters = w['filter'])

      filters.each do |f|
        next unless (v = f['resolved_value'])
        next unless values.include?(v.downcase)

        f['match_status'] = SensitiveDataRedactor::MASK
        f['resolved_value'] = SensitiveDataRedactor::MASK
      end
    end
    e[:infos][:waf_data] = JSON.dump(redacted)
  end
end

.redact_exceptions!(exceptions, values) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/sqreen/legacy/waf_redactions.rb', line 36

def redact_exceptions!(exceptions, values)
  return exceptions if values.empty?

  exceptions.each do |e|
    next(e) unless e[:infos]
    next(e) unless e[:infos][:waf]

    e[:infos][:waf].delete(:args)
  end
end