Module: LogjamAgent::Obfuscation

Included in:
LogjamAgent, Rack::Logger
Defined in:
lib/logjam_agent/obfuscation.rb

Constant Summary collapse

KEY_RE =
'[^&;=\s]+'
VAL_RE =
'[^&;=]+'
PAIR_RE =
%r{(#{KEY_RE})=(#{VAL_RE})}

Instance Method Summary collapse

Instance Method Details



15
16
17
# File 'lib/logjam_agent/obfuscation.rb', line 15

def cookie_obfuscator
  @cookie_obfuscator ||= ParameterFilter.new(obfuscated_cookies)
end

#filter_pairs(str, filter) ⇒ Object



37
38
39
40
41
# File 'lib/logjam_agent/obfuscation.rb', line 37

def filter_pairs(str, filter)
  str.gsub(PAIR_RE) do |_|
    filter.filter($1 => $2).first.join("=")
  end
end

#ip_obfuscator(ip) ⇒ Object

TODO: ipv6 obfuscation



8
9
10
# File 'lib/logjam_agent/obfuscation.rb', line 8

def ip_obfuscator(ip)
  obfuscate_ips ? ip.to_s.sub(/\d+\z/, 'XXX') : ip
end


19
20
21
# File 'lib/logjam_agent/obfuscation.rb', line 19

def obfuscate_cookie(cookie, filter = cookie_obfuscator)
  filter_pairs(cookie, filter)
end