sentry-raven 2.12.2 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/.craft.yml +15 -0
  3. data/.github/workflows/test.yml +77 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +44 -9
  6. data/.scripts/bump-version.sh +9 -0
  7. data/Gemfile +17 -25
  8. data/README.md +4 -3
  9. data/changelog.md +37 -0
  10. data/lib/raven/backtrace.rb +7 -5
  11. data/lib/raven/base.rb +5 -3
  12. data/lib/raven/breadcrumbs.rb +1 -1
  13. data/lib/raven/breadcrumbs/activesupport.rb +10 -10
  14. data/lib/raven/breadcrumbs/logger.rb +3 -3
  15. data/lib/raven/cli.rb +2 -2
  16. data/lib/raven/client.rb +12 -6
  17. data/lib/raven/configuration.rb +15 -5
  18. data/lib/raven/event.rb +5 -6
  19. data/lib/raven/instance.rb +4 -3
  20. data/lib/raven/integrations/delayed_job.rb +14 -15
  21. data/lib/raven/integrations/rack-timeout.rb +2 -3
  22. data/lib/raven/integrations/rack.rb +4 -3
  23. data/lib/raven/integrations/rails.rb +1 -0
  24. data/lib/raven/integrations/rails/active_job.rb +10 -7
  25. data/lib/raven/integrations/rails/overrides/debug_exceptions_catcher.rb +2 -2
  26. data/lib/raven/interface.rb +2 -2
  27. data/lib/raven/interfaces/stack_trace.rb +1 -1
  28. data/lib/raven/linecache.rb +5 -2
  29. data/lib/raven/logger.rb +3 -2
  30. data/lib/raven/processor/cookies.rb +16 -6
  31. data/lib/raven/processor/post_data.rb +2 -0
  32. data/lib/raven/processor/removecircularreferences.rb +1 -0
  33. data/lib/raven/processor/sanitizedata.rb +65 -17
  34. data/lib/raven/processor/utf8conversion.rb +2 -0
  35. data/lib/raven/transports.rb +4 -0
  36. data/lib/raven/transports/http.rb +5 -5
  37. data/lib/raven/utils/exception_cause_chain.rb +1 -0
  38. data/lib/raven/utils/real_ip.rb +1 -1
  39. data/lib/raven/version.rb +2 -2
  40. data/sentry-raven.gemspec +2 -2
  41. metadata +7 -12
  42. data/.travis.yml +0 -47
@@ -10,17 +10,27 @@ module Raven
10
10
  private
11
11
 
12
12
  def process_if_symbol_keys(data)
13
- data[:request][:cookies] = STRING_MASK if data[:request][:cookies]
13
+ if cookies = data.dig(:request, :cookies)
14
+ data[:request][:cookies] = generate_masked_cookies(cookies)
15
+ end
14
16
 
15
- return unless data[:request][:headers] && data[:request][:headers]["Cookie"]
16
- data[:request][:headers]["Cookie"] = STRING_MASK
17
+ if cookies_header = data[:request][:headers]["Cookie"]
18
+ data[:request][:headers]["Cookie"] = generate_masked_cookies(cookies_header)
19
+ end
17
20
  end
18
21
 
19
22
  def process_if_string_keys(data)
20
- data["request"]["cookies"] = STRING_MASK if data["request"]["cookies"]
23
+ if cookies = data.dig("request", "cookies")
24
+ data["request"]["cookies"] = generate_masked_cookies(cookies)
25
+ end
21
26
 
22
- return unless data["request"]["headers"] && data["request"]["headers"]["Cookie"]
23
- data["request"]["headers"]["Cookie"] = STRING_MASK
27
+ if cookies_header = data.dig("request", "headers", "Cookie")
28
+ data["request"]["headers"]["Cookie"] = generate_masked_cookies(cookies_header)
29
+ end
30
+ end
31
+
32
+ def generate_masked_cookies(cookies)
33
+ cookies.merge(cookies) { STRING_MASK }
24
34
  end
25
35
  end
26
36
  end
@@ -11,11 +11,13 @@ module Raven
11
11
 
12
12
  def process_if_symbol_keys(data)
13
13
  return unless data[:request][:method] == "POST"
14
+
14
15
  data[:request][:data] = STRING_MASK
15
16
  end
16
17
 
17
18
  def process_if_string_keys(data)
18
19
  return unless data["request"]["method"] == "POST"
20
+
19
21
  data["request"]["data"] = STRING_MASK
20
22
  end
21
23
  end
@@ -2,6 +2,7 @@ module Raven
2
2
  class Processor::RemoveCircularReferences < Processor
3
3
  def process(value, visited = [])
4
4
  return "(...)" if visited.include?(value.__id__)
5
+
5
6
  visited << value.__id__ if value.is_a?(Array) || value.is_a?(Hash)
6
7
 
7
8
  case value
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'json'
3
4
 
4
5
  module Raven
5
6
  class Processor::SanitizeData < Processor
6
7
  DEFAULT_FIELDS = %w(authorization password passwd secret ssn social(.*)?sec).freeze
7
- CREDIT_CARD_RE = /\b(?:3[47]\d|(?:4\d|5[1-5]|65)\d{2}|6011)\d{12}\b/
8
+ CREDIT_CARD_RE = /\b(?:3[47]\d|(?:4\d|5[1-5]|65)\d{2}|6011)\d{12}\b/.freeze
8
9
  QUERY_STRING = ['query_string', :query_string].freeze
9
10
  JSON_STARTS_WITH = ["[", "{"].freeze
10
11
 
@@ -20,22 +21,13 @@ module Raven
20
21
  def process(value, key = nil)
21
22
  case value
22
23
  when Hash
23
- !value.frozen? ? value.merge!(value) { |k, v| process v, k } : value.merge(value) { |k, v| process v, k }
24
+ sanitize_hash_value(key, value)
24
25
  when Array
25
- !value.frozen? ? value.map! { |v| process v, key } : value.map { |v| process v, key }
26
+ sanitize_array_value(key, value)
26
27
  when Integer
27
28
  matches_regexes?(key, value.to_s) ? INT_MASK : value
28
29
  when String
29
- if value =~ fields_re && (json = parse_json_or_nil(value))
30
- # if this string is actually a json obj, convert and sanitize
31
- process(json).to_json
32
- elsif matches_regexes?(key, value)
33
- STRING_MASK
34
- elsif QUERY_STRING.include?(key)
35
- sanitize_query_string(value)
36
- else
37
- value
38
- end
30
+ sanitize_string_value(key, value)
39
31
  else
40
32
  value
41
33
  end
@@ -49,6 +41,39 @@ module Raven
49
41
  @utf8_processor ||= Processor::UTF8Conversion.new
50
42
  end
51
43
 
44
+ def sanitize_hash_value(key, value)
45
+ if key =~ sensitive_fields
46
+ STRING_MASK
47
+ elsif value.frozen?
48
+ value.merge(value) { |k, v| process v, k }
49
+ else
50
+ value.merge!(value) { |k, v| process v, k }
51
+ end
52
+ end
53
+
54
+ def sanitize_array_value(key, value)
55
+ if value.frozen?
56
+ value.map { |v| process v, key }
57
+ else
58
+ value.map! { |v| process v, key }
59
+ end
60
+ end
61
+
62
+ def sanitize_string_value(key, value)
63
+ if value =~ sensitive_fields && (json = parse_json_or_nil(value))
64
+ # if this string is actually a json obj, convert and sanitize
65
+ process(json).to_json
66
+ elsif matches_regexes?(key, value)
67
+ STRING_MASK
68
+ elsif QUERY_STRING.include?(key)
69
+ sanitize_query_string(value)
70
+ elsif value =~ sensitive_fields
71
+ sanitize_sensitive_string_content(value)
72
+ else
73
+ value
74
+ end
75
+ end
76
+
52
77
  def sanitize_query_string(query_string)
53
78
  query_hash = CGI.parse(query_string)
54
79
  sanitized = utf8_processor.process(query_hash)
@@ -56,16 +81,38 @@ module Raven
56
81
  URI.encode_www_form(processed_query_hash)
57
82
  end
58
83
 
84
+ # this scrubs some sensitive info from the string content. for example:
85
+ #
86
+ # ```
87
+ # unexpected token at '{
88
+ # "role": "admin","password": "Abc@123","foo": "bar"
89
+ # }'
90
+ # ```
91
+ #
92
+ # will become
93
+ #
94
+ # ```
95
+ # unexpected token at '{
96
+ # "role": "admin","password": *******,"foo": "bar"
97
+ # }'
98
+ # ```
99
+ #
100
+ # it's particularly useful in hash or param-parsing related errors
101
+ def sanitize_sensitive_string_content(value)
102
+ value.gsub(/(#{sensitive_fields}['":]\s?(:|=>)?\s?)(".*?"|'.*?')/, '\1' + STRING_MASK)
103
+ end
104
+
59
105
  def matches_regexes?(k, v)
60
106
  (sanitize_credit_cards && v =~ CREDIT_CARD_RE) ||
61
- k =~ fields_re
107
+ k =~ sensitive_fields
62
108
  end
63
109
 
64
- def fields_re
65
- return @fields_re if instance_variable_defined?(:@fields_re)
110
+ def sensitive_fields
111
+ return @sensitive_fields if instance_variable_defined?(:@sensitive_fields)
112
+
66
113
  fields = DEFAULT_FIELDS | sanitize_fields
67
114
  fields -= sanitize_fields_excluded
68
- @fields_re = /#{fields.map do |f|
115
+ @sensitive_fields = /#{fields.map do |f|
69
116
  use_boundary?(f) ? "\\b#{f}\\b" : f
70
117
  end.join("|")}/i
71
118
  end
@@ -80,6 +127,7 @@ module Raven
80
127
 
81
128
  def parse_json_or_nil(string)
82
129
  return unless string.start_with?(*JSON_STARTS_WITH)
130
+
83
131
  JSON.parse(string)
84
132
  rescue JSON::ParserError, NoMethodError
85
133
  nil
@@ -14,6 +14,7 @@ module Raven
14
14
  !value.frozen? ? value.map! { |v| process v } : value.map { |v| process v }
15
15
  when Exception
16
16
  return value if value.message.valid_encoding?
17
+
17
18
  clean_exc = value.class.new(remove_invalid_bytes(value.message))
18
19
  clean_exc.set_backtrace(value.backtrace)
19
20
  clean_exc
@@ -27,6 +28,7 @@ module Raven
27
28
  value.force_encoding(Encoding::UTF_8)
28
29
  end
29
30
  return value if value.valid_encoding?
31
+
30
32
  remove_invalid_bytes(value)
31
33
  else
32
34
  value
@@ -13,3 +13,7 @@ module Raven
13
13
  end
14
14
  end
15
15
  end
16
+
17
+ require "raven/transports/dummy"
18
+ require "raven/transports/http"
19
+ require "raven/transports/stdout"
@@ -26,10 +26,10 @@ module Raven
26
26
  req.headers['X-Sentry-Auth'] = auth_header
27
27
  req.body = data
28
28
  end
29
- rescue Faraday::Error => ex
30
- error_info = ex.message
31
- if ex.response && ex.response[:headers]['x-sentry-error']
32
- error_info += " Error in headers is: #{ex.response[:headers]['x-sentry-error']}"
29
+ rescue Faraday::Error => e
30
+ error_info = e.message
31
+ if e.response && e.response[:headers]['x-sentry-error']
32
+ error_info += " Error in headers is: #{e.response[:headers]['x-sentry-error']}"
33
33
  end
34
34
  raise Raven::Error, error_info
35
35
  end
@@ -42,7 +42,7 @@ module Raven
42
42
  proxy = configuration.public_send(:proxy)
43
43
 
44
44
  Faraday.new(configuration.server, :ssl => ssl_configuration, :proxy => proxy) do |builder|
45
- configuration.faraday_builder.call(builder) if configuration.faraday_builder
45
+ configuration.faraday_builder&.call(builder)
46
46
  builder.response :raise_error
47
47
  builder.options.merge! faraday_opts
48
48
  builder.headers[:user_agent] = "sentry-ruby/#{Raven::VERSION}"
@@ -7,6 +7,7 @@ module Raven
7
7
  while exception.cause
8
8
  exception = exception.cause
9
9
  break if exceptions.any? { |e| e.object_id == exception.object_id }
10
+
10
11
  exceptions << exception
11
12
  end
12
13
  exceptions
@@ -13,7 +13,7 @@ module Raven
13
13
  "fc00::/7", # private IPv6 range fc00::/7
14
14
  "10.0.0.0/8", # private IPv4 range 10.x.x.x
15
15
  "172.16.0.0/12", # private IPv4 range 172.16.0.0 .. 172.31.255.255
16
- "192.168.0.0/16", # private IPv4 range 192.168.x.x
16
+ "192.168.0.0/16" # private IPv4 range 192.168.x.x
17
17
  ].map { |proxy| IPAddr.new(proxy) }
18
18
 
19
19
  attr_accessor :ip, :ip_addresses
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Raven
3
- # Freezing this constant breaks in 1.9.x
4
- VERSION = "2.12.2" # rubocop:disable Style/MutableConstant
4
+ VERSION = "3.0.2"
5
5
  end
@@ -11,11 +11,11 @@ Gem::Specification.new do |gem|
11
11
 
12
12
  gem.version = Raven::VERSION
13
13
  gem.platform = Gem::Platform::RUBY
14
- gem.required_ruby_version = '>= 1.9.0'
14
+ gem.required_ruby_version = '>= 2.3'
15
15
  gem.extra_rdoc_files = ["README.md", "LICENSE"]
16
16
  gem.files = `git ls-files | grep -Ev '^(spec|benchmarks|examples)'`.split("\n")
17
17
  gem.bindir = "exe"
18
18
  gem.executables = "raven"
19
19
 
20
- gem.add_dependency "faraday", ">= 0.7.6", "< 1.0"
20
+ gem.add_dependency "faraday", ">= 1.0"
21
21
  end
metadata CHANGED
@@ -1,23 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-raven
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.2
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-24 00:00:00.000000000 Z
11
+ date: 2020-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.7.6
20
- - - "<"
21
18
  - !ruby/object:Gem::Version
22
19
  version: '1.0'
23
20
  type: :runtime
@@ -25,9 +22,6 @@ dependencies:
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 0.7.6
30
- - - "<"
31
25
  - !ruby/object:Gem::Version
32
26
  version: '1.0'
33
27
  description: A gem that provides a client interface for the Sentry error logger
@@ -39,11 +33,13 @@ extra_rdoc_files:
39
33
  - README.md
40
34
  - LICENSE
41
35
  files:
36
+ - ".craft.yml"
37
+ - ".github/workflows/test.yml"
42
38
  - ".gitignore"
43
39
  - ".gitmodules"
44
40
  - ".rspec"
45
41
  - ".rubocop.yml"
46
- - ".travis.yml"
42
+ - ".scripts/bump-version.sh"
47
43
  - Gemfile
48
44
  - LICENSE
49
45
  - README.md
@@ -114,15 +110,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
110
  requirements:
115
111
  - - ">="
116
112
  - !ruby/object:Gem::Version
117
- version: 1.9.0
113
+ version: '2.3'
118
114
  required_rubygems_version: !ruby/object:Gem::Requirement
119
115
  requirements:
120
116
  - - ">="
121
117
  - !ruby/object:Gem::Version
122
118
  version: '0'
123
119
  requirements: []
124
- rubyforge_project:
125
- rubygems_version: 2.5.2.3
120
+ rubygems_version: 3.0.3
126
121
  signing_key:
127
122
  specification_version: 4
128
123
  summary: A gem that provides a client interface for the Sentry error logger
@@ -1,47 +0,0 @@
1
- language: ruby
2
- dist: trusty
3
- group: beta
4
- cache: bundler
5
-
6
- services:
7
- - redis-server
8
-
9
- branches:
10
- only: [master]
11
-
12
- rvm:
13
- - 2.2.10
14
- - 2.3.8
15
- - 2.4.9
16
- - 2.5.7
17
- - 2.6.5
18
-
19
- env:
20
- - RAILS_VERSION=4
21
- - RAILS_VERSION=5
22
- - RAILS_VERSION=0
23
-
24
- addons:
25
- apt:
26
- packages:
27
- - haveged
28
-
29
- before_install:
30
- - service haveged start
31
- # Pin bundler version due to https://github.com/rubygems/rubygems/issues/2055
32
- - gem install bundler -v 1.16.0
33
-
34
- matrix:
35
- include:
36
- - rvm: 1.9
37
- env: RAILS_VERSION=4
38
- - rvm: jruby-1.7.27
39
- env: JRUBY_OPTS="--dev" RAILS_VERSION=4
40
- - rvm: jruby-9.2.8.0
41
- env: JRUBY_OPTS="--dev -J-Djruby.launch.inproc=true -J-Xmx1024M" RAILS_VERSION=4
42
- - rvm: jruby-9.2.8.0
43
- env: JRUBY_OPTS="--dev -J-Djruby.launch.inproc=true -J-Xmx1024M" RAILS_VERSION=5
44
- - rvm: ruby-head
45
- env: RAILS_VERSION=0
46
- allow_failures:
47
- - rvm: ruby-head