rollbar 2.16.3 → 2.16.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
  SHA1:
3
- metadata.gz: b5cd5a741817deee8eeed5a026529a556fe4c1a1
4
- data.tar.gz: 5aa9b0225c05b77c2d8d97c273293806658a4d6c
3
+ metadata.gz: 670312ce31ce58d4bba264a778aa7f760233a368
4
+ data.tar.gz: b9a553c4fdec208957f3369d21f25717ea6e6515
5
5
  SHA512:
6
- metadata.gz: ce8a7f469fb9d0526e6f7829c3488442984aff359a8672ad86cfc120f1ef356ad7367ce496128cb77de50160bb4e55acb6f33a95ca280e41608eb34b2d3adc68
7
- data.tar.gz: d2038279771ebbf00af8674e3e8c2fc14960adac93364c5b76ce81b2ad9688d59e588a5ea1e470a40e90c9b7533749fb2f5400dfec8754f30b38ae09f40bbc09
6
+ metadata.gz: a0b506a1b5985109fb8fe4ea636172d92ad35afb318e9104c40fc3584650f6545d9756b3efe97a7513ebf7b495b355c62f477daf655bac9b95e74353db832904
7
+ data.tar.gz: b00ce0173789ae771e5dd964d80e29fc8b2a0c10b34e532932fb30ed97fe49ed283e0744a20d0338b457f01d370f35a42d97e0a50929cec372fa083783c4543b
data/Gemfile CHANGED
@@ -42,6 +42,5 @@ gem 'redis'
42
42
  gem 'resque'
43
43
  gem 'shoryuken'
44
44
  gem 'sinatra'
45
- gem 'byebug'
46
45
 
47
46
  gemspec
data/README.md CHANGED
@@ -35,4 +35,4 @@ For bug reports, please [open an issue on GitHub](https://github.com/rollbar/rol
35
35
  We're using RSpec for testing. Run the test suite with ```rake spec```. Tests for pull requests are appreciated but not required. (If you don't include a test, we'll write one before merging.)
36
36
 
37
37
  ## License
38
- Rollbar-gem is free software released under the MIT License. See [LICENSE.txt](LICENSE.txt) for details.
38
+ Rollbar-gem is free software released under the MIT License. See [LICENSE](LICENSE) for details.
@@ -43,6 +43,7 @@ module Rollbar
43
43
  attr_accessor :scrub_fields
44
44
  attr_accessor :scrub_user
45
45
  attr_accessor :scrub_password
46
+ attr_accessor :scrub_whitelist
46
47
  attr_accessor :collect_user_ip
47
48
  attr_accessor :anonymize_user_ip
48
49
  attr_accessor :user_ip_obfuscator_secret
@@ -108,6 +109,7 @@ module Rollbar
108
109
  @scrub_user = true
109
110
  @scrub_password = true
110
111
  @randomize_scrub_length = true
112
+ @scrub_whitelist = false
111
113
  @uncaught_exception_level = 'error'
112
114
  @scrub_headers = ['Authorization']
113
115
  @sidekiq_threshold = 0
@@ -63,7 +63,8 @@ module Rollbar
63
63
  :scrub_fields => Array(Rollbar.configuration.scrub_fields) + sensitive_params,
64
64
  :scrub_user => Rollbar.configuration.scrub_user,
65
65
  :scrub_password => Rollbar.configuration.scrub_password,
66
- :randomize_scrub_length => Rollbar.configuration.randomize_scrub_length
66
+ :randomize_scrub_length => Rollbar.configuration.randomize_scrub_length,
67
+ :whitelist => Rollbar.configuration.scrub_whitelist
67
68
  }
68
69
 
69
70
  Rollbar::Scrubbers::URL.call(options)
@@ -73,7 +74,8 @@ module Rollbar
73
74
  options = {
74
75
  :params => params,
75
76
  :config => Rollbar.configuration.scrub_fields,
76
- :extra_fields => sensitive_params
77
+ :extra_fields => sensitive_params,
78
+ :whitelist => Rollbar.configuration.scrub_whitelist
77
79
  }
78
80
  Rollbar::Scrubbers::Params.call(options)
79
81
  end
@@ -22,18 +22,20 @@ module Rollbar
22
22
 
23
23
  config = options[:config]
24
24
  extra_fields = options[:extra_fields]
25
+ whitelist = options[:whitelist] | false
25
26
 
26
- scrub(params, build_scrub_options(config, extra_fields))
27
+ scrub(params, build_scrub_options(config, extra_fields, whitelist))
27
28
  end
28
29
 
29
30
  private
30
31
 
31
- def build_scrub_options(config, extra_fields)
32
+ def build_scrub_options(config, extra_fields, whitelist)
32
33
  ary_config = Array(config)
33
34
 
34
35
  {
35
36
  :fields_regex => build_fields_regex(ary_config, extra_fields),
36
- :scrub_all => ary_config.include?(SCRUB_ALL)
37
+ :scrub_all => ary_config.include?(SCRUB_ALL),
38
+ :whitelist => whitelist
37
39
  }
38
40
  end
39
41
 
@@ -49,12 +51,13 @@ module Rollbar
49
51
  def scrub(params, options)
50
52
  fields_regex = options[:fields_regex]
51
53
  scrub_all = options[:scrub_all]
54
+ whitelist = options[:whitelist]
52
55
 
53
56
  return scrub_array(params, options) if params.is_a?(Array)
54
57
 
55
58
  params.to_hash.inject({}) do |result, (key, value)|
56
59
  if fields_regex === Rollbar::Encoding.encode(key).to_s
57
- result[key] = scrub_value(value)
60
+ result[key] = whitelist ? rollbar_filtered_param_value(value) : scrub_value(value)
58
61
  elsif value.is_a?(Hash)
59
62
  result[key] = scrub(value, options)
60
63
  elsif value.is_a?(Array)
@@ -64,7 +67,7 @@ module Rollbar
64
67
  elsif scrub_all
65
68
  result[key] = scrub_value(value)
66
69
  else
67
- result[key] = rollbar_filtered_param_value(value)
70
+ result[key] = whitelist ? scrub_value(value) : rollbar_filtered_param_value(value)
68
71
  end
69
72
 
70
73
  result
@@ -18,7 +18,8 @@ module Rollbar
18
18
  build_regex(options[:scrub_fields]),
19
19
  options[:scrub_user],
20
20
  options[:scrub_password],
21
- options.fetch(:randomize_scrub_length, true))
21
+ options.fetch(:randomize_scrub_length, true),
22
+ options[:whitelist])
22
23
  rescue => e
23
24
  Rollbar.logger.error("[Rollbar] There was an error scrubbing the url: #{e}, options: #{options.inspect}")
24
25
  url
@@ -26,12 +27,12 @@ module Rollbar
26
27
 
27
28
  private
28
29
 
29
- def filter(url, regex, scrub_user, scrub_password, randomize_scrub_length)
30
+ def filter(url, regex, scrub_user, scrub_password, randomize_scrub_length, whitelist)
30
31
  uri = URI.parse(url)
31
32
 
32
33
  uri.user = filter_user(uri.user, scrub_user, randomize_scrub_length)
33
34
  uri.password = filter_password(uri.password, scrub_password, randomize_scrub_length)
34
- uri.query = filter_query(uri.query, regex, randomize_scrub_length)
35
+ uri.query = filter_query(uri.query, regex, randomize_scrub_length, whitelist)
35
36
 
36
37
  uri.to_s
37
38
  end
@@ -52,12 +53,12 @@ module Rollbar
52
53
  scrub_password && password ? filtered_value(password, randomize_scrub_length) : password
53
54
  end
54
55
 
55
- def filter_query(query, regex, randomize_scrub_length)
56
+ def filter_query(query, regex, randomize_scrub_length, whitelist)
56
57
  return query unless query
57
58
 
58
59
  params = decode_www_form(query)
59
60
 
60
- encoded_query = encode_www_form(filter_query_params(params, regex, randomize_scrub_length))
61
+ encoded_query = encode_www_form(filter_query_params(params, regex, randomize_scrub_length, whitelist))
61
62
 
62
63
  # We want this to rebuild array params like foo[]=1&foo[]=2
63
64
  URI.escape(CGI.unescape(encoded_query))
@@ -71,9 +72,13 @@ module Rollbar
71
72
  URI.encode_www_form(params)
72
73
  end
73
74
 
74
- def filter_query_params(params, regex, randomize_scrub_length)
75
+ def filter_query_params(params, regex, randomize_scrub_length, whitelist)
75
76
  params.map do |key, value|
76
- [key, filter_key?(key, regex) ? filtered_value(value, randomize_scrub_length) : value]
77
+ if whitelist
78
+ [key, filter_key?(key, regex) ? value : filtered_value(value, randomize_scrub_length)]
79
+ else
80
+ [key, filter_key?(key, regex) ? filtered_value(value, randomize_scrub_length) : value]
81
+ end
77
82
  end
78
83
  end
79
84
 
@@ -1,3 +1,3 @@
1
1
  module Rollbar
2
- VERSION = '2.16.3'
2
+ VERSION = '2.16.4'
3
3
  end
@@ -339,7 +339,7 @@ END
339
339
  end
340
340
  let(:expected_js_options) do
341
341
  {
342
- :foo => :bar,
342
+ :foo => 'bar',
343
343
  :payload => {
344
344
  :a => 42,
345
345
  :person => {
@@ -354,8 +354,11 @@ END
354
354
  it 'adds the person data to the configuration' do
355
355
  _, _, response = subject.call(env)
356
356
  new_body = response.body.join
357
-
358
- expect(new_body).to include(expected_js_options.to_json)
357
+
358
+ rollbar_config = new_body[/var _rollbarConfig = (.*);<\/script>/, 1]
359
+ rollbar_config = JSON.parse(rollbar_config, { :symbolize_names => true})
360
+
361
+ expect(rollbar_config).to eql(expected_js_options)
359
362
  end
360
363
 
361
364
  context 'when the person data is nil' do
@@ -18,12 +18,14 @@ describe Rollbar::RequestDataExtractor do
18
18
  let(:url) { 'http://this-is-the-url.com/foobar?param1=value1' }
19
19
  let(:sensitive_params) { [:param1, :param2] }
20
20
  let(:scrub_fields) { [:password, :secret] }
21
+ let(:scrub_whitelist) { false }
21
22
 
22
23
  before do
23
24
  allow(Rollbar.configuration).to receive(:scrub_fields).and_return(scrub_fields)
24
25
  allow(Rollbar.configuration).to receive(:scrub_user).and_return(true)
25
26
  allow(Rollbar.configuration).to receive(:scrub_password).and_return(true)
26
27
  allow(Rollbar.configuration).to receive(:randomize_secret_length).and_return(true)
28
+ allow(Rollbar.configuration).to receive(:scrub_whitelist).and_return(false)
27
29
  end
28
30
 
29
31
  it 'calls the scrubber with the correct options' do
@@ -32,7 +34,8 @@ describe Rollbar::RequestDataExtractor do
32
34
  :scrub_fields => [:password, :secret, :param1, :param2],
33
35
  :scrub_user => true,
34
36
  :scrub_password => true,
35
- :randomize_scrub_length => true
37
+ :randomize_scrub_length => true,
38
+ :whitelist => false
36
39
  }
37
40
 
38
41
  expect(Rollbar::Scrubbers::URL).to receive(:call).with(expected_options)
@@ -50,16 +53,19 @@ describe Rollbar::RequestDataExtractor do
50
53
  end
51
54
  let(:sensitive_params) { [:param1, :param2] }
52
55
  let(:scrub_fields) { [:password, :secret] }
56
+ let(:scrub_whitelist) { false }
53
57
 
54
58
  before do
55
59
  allow(Rollbar.configuration).to receive(:scrub_fields).and_return(scrub_fields)
60
+ allow(Rollbar.configuration).to receive(:scrub_whitelist).and_return(scrub_whitelist)
56
61
  end
57
62
 
58
63
  it 'calls the scrubber with the correct options' do
59
64
  expected_options = {
60
65
  :params => params,
61
66
  :config => scrub_fields,
62
- :extra_fields => sensitive_params
67
+ :extra_fields => sensitive_params,
68
+ :whitelist => scrub_whitelist
63
69
  }
64
70
 
65
71
  expect(Rollbar::Scrubbers::Params).to receive(:call).with(expected_options)
@@ -16,10 +16,16 @@ describe Rollbar::Scrubbers::Params do
16
16
 
17
17
  describe '#call' do
18
18
  let(:options) do
19
- {
19
+ options = {
20
20
  :params => params,
21
21
  :config => scrub_config
22
22
  }
23
+
24
+ if defined? whitelist
25
+ options[:whitelist] = whitelist
26
+ end
27
+
28
+ options
23
29
  end
24
30
 
25
31
  context 'with scrub fields configured' do
@@ -271,6 +277,7 @@ describe Rollbar::Scrubbers::Params do
271
277
 
272
278
  context 'with :scrub_all option' do
273
279
  let(:scrub_config) { :scrub_all }
280
+
274
281
  let(:params) do
275
282
  {
276
283
  :foo => 'bar',
@@ -298,6 +305,174 @@ describe Rollbar::Scrubbers::Params do
298
305
  expect(subject.call(options)).to be_eql_hash_with_regexes(result)
299
306
  end
300
307
  end
308
+
309
+ context 'with :whitelist option' do
310
+ let(:scrub_config) do
311
+ [:secret, :password]
312
+ end
313
+
314
+ let(:whitelist) { true }
315
+
316
+ context 'with Array object' do
317
+ let(:params) do
318
+ [
319
+ {
320
+ :foo => 'bar',
321
+ :secret => 'the-secret',
322
+ :password => 'the-password',
323
+ :password_confirmation => 'the-password'
324
+ }
325
+ ]
326
+ end
327
+ let(:result) do
328
+ [
329
+ {
330
+ :foo => /\*+/,
331
+ :secret => 'the-secret',
332
+ :password => 'the-password',
333
+ :password_confirmation => 'the-password'
334
+ }
335
+ ]
336
+ end
337
+
338
+ it 'scrubs the required parameters' do
339
+ expect(subject.call(options).first).to be_eql_hash_with_regexes(result.first)
340
+ end
341
+ end
342
+
343
+ context 'with simple Hash' do
344
+ let(:params) do
345
+ {
346
+ :foo => 'bar',
347
+ :secret => 'the-secret',
348
+ :password => 'the-password',
349
+ :password_confirmation => 'the-password'
350
+ }
351
+ end
352
+ let(:result) do
353
+ {
354
+ :foo => /\*+/,
355
+ :secret => 'the-secret',
356
+ :password => 'the-password',
357
+ :password_confirmation => 'the-password'
358
+ }
359
+ end
360
+
361
+ it 'scrubs the required parameters' do
362
+ expect(subject.call(options)).to be_eql_hash_with_regexes(result)
363
+ end
364
+ end
365
+
366
+ context 'with nested Hash' do
367
+ let(:scrub_config) do
368
+ super().push(:param)
369
+ end
370
+
371
+ let(:params) do
372
+ {
373
+ :foo => 'bar',
374
+ :extra => {
375
+ :secret => 'the-secret',
376
+ :password => 'the-password',
377
+ :password_confirmation => 'the-password'
378
+ },
379
+ :other => {
380
+ :param => 'filtered',
381
+ :to_scrub => 'to_scrub'
382
+ }
383
+ }
384
+ end
385
+ let(:result) do
386
+ {
387
+ :foo => /\*+/,
388
+ :extra => {
389
+ :secret => 'the-secret',
390
+ :password => 'the-password',
391
+ :password_confirmation => 'the-password'
392
+ },
393
+ :other => {
394
+ :param => 'filtered',
395
+ :to_scrub => /\*+/
396
+ }
397
+ }
398
+ end
399
+
400
+ it 'scrubs the required parameters' do
401
+ expect(subject.call(options)).to be_eql_hash_with_regexes(result)
402
+ end
403
+ end
404
+
405
+ context 'with nested Array' do
406
+ let(:scrub_config) do
407
+ super().push(:param)
408
+ end
409
+
410
+ let(:params) do
411
+ {
412
+ :foo => 'bar',
413
+ :extra => [{
414
+ :secret => 'the-secret',
415
+ :password => 'the-password',
416
+ :password_confirmation => 'the-password'
417
+ }],
418
+ :other => [{
419
+ :param => 'filtered',
420
+ :to_scrub => 'to_scrub'
421
+ }]
422
+ }
423
+ end
424
+ let(:result) do
425
+ {
426
+ :foo => /\*+/,
427
+ :extra => [{
428
+ :secret => 'the-secret',
429
+ :password => 'the-password',
430
+ :password_confirmation => 'the-password'
431
+ }],
432
+ :other => [{
433
+ :param => 'filtered',
434
+ :to_scrub => /\*+/
435
+ }]
436
+ }
437
+ end
438
+
439
+ it 'scrubs the required parameters' do
440
+ expect(subject.call(options)).to be_eql_hash_with_regexes(result)
441
+ end
442
+ end
443
+
444
+ context 'with skipped instance' do
445
+ let(:tempfile) { Tempfile.new('foo') }
446
+ let(:params) do
447
+ {
448
+ :foo => 'bar',
449
+ :extra => [{
450
+ :secret => 'the-secret',
451
+ :password => 'the-password',
452
+ :password_confirmation => 'the-password',
453
+ :skipped => tempfile
454
+ }]
455
+ }
456
+ end
457
+ let(:result) do
458
+ {
459
+ :foo => /\*+/,
460
+ :extra => [{
461
+ :secret => 'the-secret',
462
+ :password => 'the-password',
463
+ :password_confirmation => 'the-password',
464
+ :skipped => "Skipped value of class 'Tempfile'"
465
+ }]
466
+ }
467
+ end
468
+
469
+ after { tempfile.close }
470
+
471
+ it 'scrubs the required parameters' do
472
+ expect(subject.call(options)).to be_eql_hash_with_regexes(result)
473
+ end
474
+ end
475
+ end
301
476
  end
302
477
  end
303
478
 
@@ -4,13 +4,19 @@ require 'rollbar/scrubbers/url'
4
4
 
5
5
  describe Rollbar::Scrubbers::URL do
6
6
  let(:options) do
7
- {
7
+ options = {
8
8
  :url => url,
9
9
  :scrub_fields => [:password, :secret],
10
10
  :scrub_user => false,
11
11
  :scrub_password => false,
12
12
  :randomize_scrub_length => true
13
13
  }
14
+
15
+ if defined? whitelist
16
+ options[:whitelist] = whitelist
17
+ end
18
+
19
+ options
14
20
  end
15
21
 
16
22
  describe '#call' do
@@ -132,5 +138,74 @@ describe Rollbar::Scrubbers::URL do
132
138
  end
133
139
  end
134
140
  end
141
+
142
+ context 'in whitelist mode' do
143
+
144
+ let(:whitelist) { true }
145
+
146
+ context 'with ruby different from 1.8' do
147
+ next unless Rollbar::LanguageSupport.can_scrub_url?
148
+
149
+ context 'cannot scrub URLs' do
150
+
151
+ let(:url) { 'http://user:password@foo.com/some-interesting-path#fragment' }
152
+
153
+ it 'returns the URL without any change' do
154
+ expect(subject.call(options)).to be_eql(url)
155
+ end
156
+ end
157
+
158
+ context 'scrubbing user and password' do
159
+
160
+ let(:options) do
161
+ {
162
+ :url => url,
163
+ :scrub_fields => [],
164
+ :scrub_password => true,
165
+ :scrub_user => true,
166
+ :whitelist => whitelist
167
+ }
168
+ end
169
+
170
+ let(:url) { 'http://user:password@foo.com/some-interesting-path#fragment' }
171
+
172
+ it 'returns the URL without any change' do
173
+ expected_url = /http:\/\/\*{3,8}:\*{3,8}@foo.com\/some-interesting\-path#fragment/
174
+
175
+ expect(subject.call(options)).to match(expected_url)
176
+ end
177
+ end
178
+
179
+ context 'with params to be filtered' do
180
+ let(:options) do
181
+ {
182
+ :url => url,
183
+ :scrub_fields => [:dont_scrub],
184
+ :scrub_password => false,
185
+ :scrub_user => false,
186
+ :whitelist => whitelist
187
+ }
188
+ end
189
+
190
+ let(:url) { 'http://foo.com/some-interesting-path?foo=bar&password=mypassword&secret=somevalue&dont_scrub=foo#fragment' }
191
+
192
+ it 'returns the URL with some params filtered' do
193
+ expected_url = /http:\/\/foo.com\/some-interesting-path\?foo=\*{3,8}&password=\*{3,8}&secret=\*{3,8}&dont_scrub=foo#fragment/
194
+
195
+ expect(subject.call(options)).to match(expected_url)
196
+ end
197
+
198
+ context 'having array params' do
199
+ let(:url) { 'http://foo.com/some-interesting-path?foo=bar&password[]=mypassword&password[]=otherpassword&secret=somevalue&dont_scrub=foo#fragment' }
200
+
201
+ it 'returns the URL with some params filtered' do
202
+ expected_url = /http:\/\/foo.com\/some-interesting-path\?foo=\*{3,8}&password\[\]=\*{3,8}&password\[\]=\*{3,8}&secret=\*{3,8}&dont_scrub=foo#fragment/
203
+
204
+ expect(subject.call(options)).to match(expected_url)
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end
135
210
  end
136
211
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.16.3
4
+ version: 2.16.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rollbar, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-12 00:00:00.000000000 Z
11
+ date: 2018-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json