logjam_agent 0.38.2 → 0.38.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 623b528c086e5359f9824c6ed231207340d9abc8fb1046f2763200404e9c3ee9
4
- data.tar.gz: 0d7de9ffac6e355314388c15c9e6fb0d18f1c5ad723dce7c9b19ef64a864fa1c
3
+ metadata.gz: 40a7fc87817d5d47fd6ec90066a0f383436cb25f3f50ee835c0372c2a7f895e2
4
+ data.tar.gz: c5a89ddd87c4cc14191d9c69a16c3a0a91790ef8cbc513e35635b30f4a0a2c93
5
5
  SHA512:
6
- metadata.gz: 24d13d8931fc1a3ff1ec13a0617f941798719ccb9cec724d2934f0b80fc7365027029996b867194b60d780589fbfc7b8f391102d16cca28b7b9a5f6fda2668ae
7
- data.tar.gz: c130018a95950bb0dfe32afe866f9ce891685ed37edd845b96f76fbe0c97b869bbcb08ba185a9b7f028b3eb9ff98a0a2a7f360a4292efcdb6d840b01a0e0c29e
6
+ metadata.gz: 239cf4fda9b20bf22e65d5d7454f642f453cf34b4e5f4adcade67d7dae2233d6e596c35f70fbd9a9f4c68cf4f2e847a80a7f310002719d5f9a9852633f8cfe95
7
+ data.tar.gz: d376a763eee26ec914c930afeb9379119c2f4a6b03e28aa45d1ff8110f5119f4974dc899054f952d647141db84f70e37620312ef29887b00ea3eb2bffe284723
@@ -0,0 +1,44 @@
1
+ module LogjamAgent
2
+ module Obfuscation
3
+
4
+ mattr_accessor :obfuscate_ips
5
+ self.obfuscate_ips = false
6
+
7
+ # TODO: ipv6 obfuscation
8
+ def ip_obfuscator(ip)
9
+ obfuscate_ips ? ip.to_s.sub(/\d+\z/, 'XXX') : ip
10
+ end
11
+
12
+ mattr_accessor :obfuscated_cookies
13
+ self.obfuscated_cookies = [/_session\z/]
14
+
15
+ def cookie_obfuscator
16
+ @cookie_obfuscator ||= ParameterFilter.new(obfuscated_cookies)
17
+ end
18
+
19
+ def obfuscate_cookie(cookie, filter = cookie_obfuscator)
20
+ filter_pairs(cookie, filter)
21
+ end
22
+
23
+ begin
24
+ # rails 6.1 and higher
25
+ require "active_support/parameter_filter"
26
+ ParameterFilter = ::ActiveSupport::ParameterFilter
27
+ rescue LoadError
28
+ # rails 6.0 and older
29
+ require "action_dispatch/http/parameter_filter"
30
+ ParameterFilter = ::ActionDispatch::Http::ParameterFilter
31
+ end
32
+
33
+ KEY_RE = '[^&;=\s]+'
34
+ VAL_RE = '[^&;=]+'
35
+ PAIR_RE = %r{(#{KEY_RE})=(#{VAL_RE})}
36
+
37
+ def filter_pairs(str, filter)
38
+ str.gsub(PAIR_RE) do |_|
39
+ filter.filter($1 => $2).first.join("=")
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -216,8 +216,7 @@ module LogjamAgent
216
216
  CONTENT_LENGTH = 'CONTENT_LENGTH'
217
217
  COOKIE = 'HTTP_COOKIE'
218
218
 
219
- KV_RE = '[^&;=]+'
220
- PAIR_RE = %r{(#{KV_RE})=(#{KV_RE})}
219
+ include Obfuscation
221
220
 
222
221
  def extract_headers(request, filter)
223
222
  headers = request.env.reject{|k,v| k =~ HIDDEN_VARIABLES }
@@ -225,15 +224,11 @@ module LogjamAgent
225
224
  headers = filter.filter(headers)
226
225
 
227
226
  if referer = headers[REFERER]
228
- headers[REFERER] = referer.gsub(PAIR_RE) do |_|
229
- filter.filter($1 => $2).first.join("=")
230
- end
227
+ headers[REFERER] = filter_pairs(referer, filter)
231
228
  end
232
229
 
233
- if (cookie = headers[COOKIE]) && LogjamAgent.obfuscated_cookies.present?
234
- headers[COOKIE] = cookie.gsub(PAIR_RE) do |_|
235
- LogjamAgent.cookie_obfuscator.filter($1 => $2).first.join("=")
236
- end
230
+ if (cookie = headers[COOKIE]) && obfuscated_cookies.present?
231
+ headers[COOKIE] = obfuscate_cookie(cookie, cookie_obfuscator)
237
232
  end
238
233
 
239
234
  headers.keys.each do |k|
@@ -1,3 +1,3 @@
1
1
  module LogjamAgent
2
- VERSION = "0.38.2"
2
+ VERSION = "0.38.4"
3
3
  end
data/lib/logjam_agent.rb CHANGED
@@ -10,6 +10,7 @@ end
10
10
 
11
11
  require "logjam_agent/version"
12
12
  require "logjam_agent/util"
13
+ require "logjam_agent/obfuscation"
13
14
  require "logjam_agent/zmq_forwarder"
14
15
  require "logjam_agent/forwarders"
15
16
  require "logjam_agent/request"
@@ -77,26 +78,7 @@ module LogjamAgent
77
78
  mattr_accessor :ensure_ping_at_exit
78
79
  self.ensure_ping_at_exit = true
79
80
 
80
- mattr_accessor :obfuscate_ips
81
- self.obfuscate_ips = false
82
-
83
- # TODO: ipv6 obfuscation
84
- def self.ip_obfuscator(ip)
85
- obfuscate_ips ? ip.to_s.sub(/\d+\z/, 'XXX') : ip
86
- end
87
-
88
- mattr_accessor :obfuscated_cookies
89
- self.obfuscated_cookies = [/_session\z/]
90
-
91
- def self.cookie_obfuscator
92
- @cookie_obfuscator ||=
93
- if defined?(ActiveSupport::ParameterFilter)
94
- ActiveSupport::ParameterFilter.new(obfuscated_cookies)
95
- else
96
- ActionDispatch::Http::ParameterFilter.new(obfuscated_cookies)
97
- end
98
- end
99
-
81
+ extend Obfuscation
100
82
  extend RequestHandling
101
83
  extend SelectiveLogging
102
84
 
@@ -0,0 +1,27 @@
1
+ require_relative "test_helper.rb"
2
+
3
+ module LogjamAgent
4
+ class ObfuscatorTest < MiniTest::Test
5
+ include Obfuscation
6
+
7
+ test "obfuscates session cookie by default" do
8
+ assert_equal "_session=[FILTERED]", obfuscate_cookie("_session=data")
9
+ assert_equal "my_session=[FILTERED]", obfuscate_cookie("my_session=mdata")
10
+ assert_equal "blabber=1; _session=[FILTERED]", obfuscate_cookie("blabber=1; _session=data")
11
+ assert_equal "blabber=1; _session=[FILTERED]; blubber=2", obfuscate_cookie("blabber=1; _session=data; blubber=2")
12
+ end
13
+
14
+ test "obfuscates with complex regex" do
15
+ filter = ParameterFilter.new([/(login|_session)\z/])
16
+ assert_equal "_session=[FILTERED]; login=[FILTERED]", obfuscate_cookie("_session=my_session; login=foo", filter)
17
+ assert_equal "_session=[FILTERED]; my_login=[FILTERED]", obfuscate_cookie("_session=my_session; my_login=foo", filter)
18
+ end
19
+
20
+ test "obfuscates with exact matches" do
21
+ filter = ParameterFilter.new([/\A(login|.*_session)\z/])
22
+ assert_equal "_session=[FILTERED]; login=[FILTERED]", obfuscate_cookie("_session=my_session; login=foo", filter)
23
+ assert_equal "_session=[FILTERED]; my_login=foo", obfuscate_cookie("_session=my_session; my_login=foo", filter)
24
+ assert_equal "my_session=[FILTERED]; my_login=foo", obfuscate_cookie("my_session=my_session; my_login=foo", filter)
25
+ end
26
+ end
27
+ end
data/test/sinatra_app.rb CHANGED
@@ -1,12 +1,15 @@
1
1
  $:.unshift File.expand_path('../../lib', __FILE__)
2
2
 
3
3
  require 'logjam_agent/sinatra'
4
+ require 'sinatra/cookies'
4
5
 
5
6
  class SinatraTestApp < Sinatra::Base
6
7
  register LogjamAgent::Sinatra
7
8
 
8
9
  use LogjamAgent::Sinatra::Middleware
9
10
 
11
+ helpers Sinatra::Cookies
12
+
10
13
  configure do
11
14
  set :root, File.expand_path('../..', __FILE__)
12
15
  set :environment, :test
@@ -24,6 +27,8 @@ class SinatraTestApp < Sinatra::Base
24
27
  end
25
28
 
26
29
  get '/index' do
30
+ cookies[:foo] = 'bar'
31
+ cookies[:frerks] = "no micro"
27
32
  logger.info 'Hello World!'
28
33
  'Hello World!'
29
34
  end
@@ -1,6 +1,7 @@
1
1
  $:.unshift File.expand_path('../../lib', __FILE__)
2
2
 
3
3
  require 'logjam_agent/sinatra'
4
+ require 'sinatra/cookies'
4
5
 
5
6
  use LogjamAgent::Sinatra::Middleware
6
7
 
@@ -27,5 +28,7 @@ end
27
28
  get '/index' do
28
29
  action_name "Simple#index"
29
30
  logger.info 'Hello World!'
31
+ cookies[:foo] = 'bar'
32
+ cookies[:frerks] = "no micro"
30
33
  'Hello World!'
31
34
  end
@@ -12,7 +12,10 @@ module LogjamAgent
12
12
  end
13
13
 
14
14
  def test_root
15
- get '/index?mumu=1&password=5'
15
+ cookie_jar = ::Rack::Test::CookieJar.new
16
+ cookie_jar['foo'] = 'bar'
17
+ cookie_jar['baz'] = 'gni'
18
+ get '/index?mumu=1&password=5', {}, 'HTTP_COOKIE' => cookie_jar.for(nil)
16
19
  assert_equal 'Hello World!', last_response.body
17
20
  end
18
21
 
data/test/sinatra_test.rb CHANGED
@@ -24,7 +24,10 @@ module LogjamAgent
24
24
  end
25
25
 
26
26
  def test_root
27
- get '/index?mumu=1&password=5'
27
+ cookie_jar = ::Rack::Test::CookieJar.new
28
+ cookie_jar['foo'] = 'bar'
29
+ cookie_jar['baz'] = 'gni'
30
+ get '/index?mumu=1&password=5', {}, 'HTTP_COOKIE' => cookie_jar.for(nil)
28
31
  assert_equal 'Hello World!', last_response.body
29
32
  assert_equal 200, last_response.status
30
33
 
@@ -49,6 +52,8 @@ module LogjamAgent
49
52
  assert_equal method, "GET"
50
53
  assert_equal url, "/index?mumu=1&password=[FILTERED]"
51
54
  assert_equal(query_parameters, { "mumu" => "1", "password" => "[FILTERED]" })
55
+ assert_match(/baz=gni/, request_info["headers"]["Cookie"])
56
+ assert_match(/foo=\[FILTERED\]/, request_info["headers"]["Cookie"])
52
57
  end
53
58
 
54
59
  end
data/test/test_helper.rb CHANGED
@@ -20,6 +20,9 @@ require "logjam_agent/receiver"
20
20
  # for Sinatra
21
21
  ENV['RACK_ENV'] = "test"
22
22
 
23
+ # Obfuscate the foo cookie.
24
+ LogjamAgent.obfuscated_cookies = [/\A(foo|.*_session)\z/]
25
+
23
26
  class MockLogDev
24
27
  attr_reader :lines
25
28
  def initialize
metadata CHANGED
@@ -1,183 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logjam_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.38.2
4
+ version: 0.38.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-02 00:00:00.000000000 Z
11
+ date: 2023-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: i18n
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: snappy
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: lz4-ruby
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: oj
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: byebug
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: minitest
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: mocha
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: sinatra
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: rack-test
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: appraisal
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: simplecov
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
13
  - !ruby/object:Gem::Dependency
182
14
  name: activesupport
183
15
  requirement: !ruby/object:Gem::Requirement
@@ -252,6 +84,7 @@ files:
252
84
  - lib/logjam_agent/logging_attributes.rb
253
85
  - lib/logjam_agent/middleware.rb
254
86
  - lib/logjam_agent/monkey_patches/ffi-rzmq-patch.rb
87
+ - lib/logjam_agent/obfuscation.rb
255
88
  - lib/logjam_agent/rack/logger.rb
256
89
  - lib/logjam_agent/rack/rails_support.rb
257
90
  - lib/logjam_agent/rack/sinatra_request.rb
@@ -266,6 +99,7 @@ files:
266
99
  - lib/logjam_agent/version.rb
267
100
  - lib/logjam_agent/zmq_forwarder.rb
268
101
  - test/json_logging_test.rb
102
+ - test/obfuscator_test.rb
269
103
  - test/request_test.rb
270
104
  - test/selective_logging_test.rb
271
105
  - test/sinatra_app.rb
@@ -300,6 +134,7 @@ specification_version: 4
300
134
  summary: Logjam client library to be used with logjam
301
135
  test_files:
302
136
  - test/json_logging_test.rb
137
+ - test/obfuscator_test.rb
303
138
  - test/request_test.rb
304
139
  - test/selective_logging_test.rb
305
140
  - test/sinatra_app.rb