sentry-sanitizer 0.1.0 → 0.2.0

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: d2531529a81144119d0073bb8cadf32b44b98bf7704e78e5bdb7005db626a57b
4
- data.tar.gz: 0cad872dcaff97f50a97739794b9c625bcad81aad616c6fb2f59b568fd3b938c
3
+ metadata.gz: aa6e89bd5636947019b12574187eb515d000a6d93bd48c3895bf3bf24e7564ca
4
+ data.tar.gz: 9a69894f2ed6903496162584c1ccb920d0e5a6ab3f75dc333c6c12dead8fc031
5
5
  SHA512:
6
- metadata.gz: 9ecae6a901360c2a74f81e4d682ce6531bd98bf411aa6a68b84617b85dec1d90bcec41c730a4dfecc2e534afc8676ddeb3247c24b5f33e5dbb6f0e230bbed354
7
- data.tar.gz: ec6e59364de9fd75d8a02f879c4449259ecbd4e895f9bcfe35d3be8cde4b5907aab4e9f3af634b5deee2c8137e2fd50c624c7960bf0978005ee30a4f22f38ffb
6
+ metadata.gz: 54510f582c6e9434700ce3db8735566bd4ef1af3b2fd2caaaeb1cb016503d2a84a22ad39d3637ba34fbb95ad86274508c72badb56a4b458278ef7afbd64f52f2
7
+ data.tar.gz: fdd38c2cce91b32436522520d318f7c0c7f54f87777c1bcdfc80e77109ff43518807adf560aed42c99a8b4bf4cc2abdcd806a56f6a9328836e6b159da0ae5deb
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ .ruby-version
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sentry-sanitizer (0.2.0)
5
+ sentry-ruby (~> 4.2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (11.1.3)
11
+ coderay (1.1.3)
12
+ concurrent-ruby (1.1.8)
13
+ diff-lcs (1.4.4)
14
+ faraday (1.3.0)
15
+ faraday-net_http (~> 1.0)
16
+ multipart-post (>= 1.2, < 3)
17
+ ruby2_keywords
18
+ faraday-net_http (1.0.1)
19
+ method_source (1.0.0)
20
+ multipart-post (2.1.1)
21
+ pry (0.13.1)
22
+ coderay (~> 1.1)
23
+ method_source (~> 1.0)
24
+ pry-byebug (3.9.0)
25
+ byebug (~> 11.0)
26
+ pry (~> 0.13.0)
27
+ rack (2.2.3)
28
+ rake (10.5.0)
29
+ rspec (3.10.0)
30
+ rspec-core (~> 3.10.0)
31
+ rspec-expectations (~> 3.10.0)
32
+ rspec-mocks (~> 3.10.0)
33
+ rspec-core (3.10.1)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-expectations (3.10.1)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-mocks (3.10.2)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-support (3.10.2)
42
+ ruby2_keywords (0.0.4)
43
+ sentry-ruby (4.2.0)
44
+ concurrent-ruby (~> 1.0, >= 1.0.2)
45
+ faraday (>= 1.0)
46
+ sentry-ruby-core (= 4.2.0)
47
+ sentry-ruby-core (4.2.0)
48
+ concurrent-ruby
49
+ faraday
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ bundler (>= 1.17)
56
+ pry-byebug
57
+ rack
58
+ rake (~> 10.0)
59
+ rspec (~> 3.0)
60
+ sentry-sanitizer!
61
+
62
+ BUNDLED WITH
63
+ 2.1.4
data/Rakefile CHANGED
@@ -1,9 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- require "bundler/gem_helper"
5
- Bundler::GemHelper.install_tasks(name: "sentry-sanitizer")
6
-
7
4
  RSpec::Core::RakeTask.new(:spec)
8
5
 
9
6
  task :default => :spec
@@ -1,60 +1,83 @@
1
1
  module Sentry
2
2
  module Sanitizer
3
3
  class Cleaner
4
- HOOK = ->(event, hint) do
5
- Sentry::Sanitizer::Cleaner.new(Sentry.configuration.sanitize).call(event)
6
-
7
- event
8
- end.freeze
9
-
10
4
  DEFAULT_MASK = '[FILTERED]'.freeze
11
5
  DEFAULT_SENSITIVE_HEADERS = %w[
12
6
  Authorization
13
7
  X-Xsrf-Token
14
8
  ].freeze
15
9
 
16
- private_constant :SENSITIVE_HEADERS
10
+ private_constant :DEFAULT_SENSITIVE_HEADERS
17
11
 
18
12
  def initialize(config)
19
13
  @fields = config.fields || []
20
- @http_headers = config.http_headers || []
21
- @cookies = config.cookies || false
14
+ @http_headers = config.http_headers || false
15
+ @do_cookies = config.cookies || false
22
16
  end
23
17
 
24
18
  def call(event)
25
19
  if event.is_a?(Sentry::Event)
26
- event.request = sanitize_request(event.request) if event.request
27
- event.extra = sanitize_hash(event.extra) if event.extra
20
+ sanitize_request(event, :object) if event.request
21
+ event.extra = sanitize_data(event.extra)
22
+ elsif event.is_a?(Hash)
23
+ sanitize_request(event, :stringified_hash) if event['request']
24
+ sanitize_request(event, :symbolized_hash) if event[:request]
25
+ event['extra'] = sanitize_data(event['extra']) if event['extra']
26
+ event[:extra] = sanitize_data(event[:extra]) if event[:extra]
28
27
  end
29
28
  end
30
29
 
31
- def sanitize_request(request)
32
- request.data = sanitize_hash(request.data) if fields
33
- request.headers = sanitize_headers(request.headers) if http_headers
34
- request.cookies = sanitize_cookies(request.cookies) if cookies
30
+ def sanitize_request(event, type)
31
+ case type
32
+ when :object
33
+ event.request.data = sanitize_data(event.request.data)
34
+ event.request.headers = sanitize_headers(event.request.headers)
35
+ event.request.cookies = sanitize_cookies(event.request.cookies)
36
+ when :stringified_hash
37
+ event['request']['data'] = sanitize_data(event['request']['data'])
38
+ event['request']['headers'] = sanitize_headers(event['request']['headers'])
39
+ event['request']['cookies'] = sanitize_cookies(event['request']['cookies'])
40
+ when :symbolized_hash
41
+ event[:request][:data] = sanitize_data(event[:request][:data])
42
+ event[:request][:headers] = sanitize_headers(event[:request][:headers])
43
+ event[:request][:cookies] = sanitize_cookies(event[:request][:cookies])
44
+ end
35
45
  end
36
46
 
37
- def sanitize_hash(hash)
38
- return if hash.blank?
47
+ def sanitize_data(hash)
48
+ return hash unless hash.is_a? Hash
49
+ return hash unless fields.size.positive?
39
50
 
40
51
  sanitize_value(hash, nil)
41
52
  end
42
53
 
43
54
  private
44
55
 
45
- attr_reader :fields, :http_headers, :cookies
56
+ attr_reader :fields, :http_headers, :do_cookies
46
57
 
47
58
  # Sanitize specified headers
48
59
  def sanitize_headers(headers)
49
- headers.keys.select { |key| key.match?(sensitive_headers) }.each do |key|
50
- headers[key] = DEFAULT_MASK
51
- end
60
+ case headers
61
+ when TrueClass
62
+ headers.transform_values { DEFAULT_MASK }
63
+ when Hash
64
+ return headers unless http_headers.size.positive?
52
65
 
53
- headers
66
+ headers.keys.select { |key| key.match?(sensitive_headers) }.each do |key|
67
+ headers[key] = DEFAULT_MASK
68
+ end
69
+
70
+ headers
71
+ else
72
+ headers
73
+ end
54
74
  end
55
75
 
56
76
  # Sanitize all cookies
57
77
  def sanitize_cookies(cookies)
78
+ return cookies unless cookies.is_a? Hash
79
+ return cookies unless do_cookies
80
+
58
81
  cookies.transform_values { DEFAULT_MASK }
59
82
  end
60
83
 
@@ -1,54 +1,24 @@
1
+ require 'sentry/configuration'
1
2
  require 'sentry/sanitizer/cleaner'
3
+ require 'sentry/sanitizer/configuration_mixin'
2
4
 
3
5
  module Sentry
4
6
  # Monkey-patching Sentry::Configuration
5
7
  class Configuration
6
- # Allow adding multiple hooks for this extension
7
- def before_send=(value)
8
- super
8
+ # Add sanitizing configuration
9
+ attr_reader :sanitize
9
10
 
10
- return value if value == false
11
+ # Patch before_send method so it could support more than one call
12
+ prepend Sentry::Sanitizer::ConfigurationMixin
11
13
 
12
- @before_send_hook_list ||= []
13
- @before_send_hook_list << value
14
-
15
- @before_send = ->(event, hint) {
16
- @before_send_hook_list.each do |hook|
17
- event = hook.call(event, hint)
18
- end
19
- }
20
- end
21
-
22
- def sanitize
14
+ add_post_initialization_callback do
23
15
  @sanitize ||= Sentry::Sanitizer::Configuration.new
24
- end
25
16
 
26
- def sanitize_fields=(fields)
27
- unless fields.is_a? Array
28
- raise ArgumentError, 'sanitize_fields must be array'
29
- end
17
+ self.before_send = ->(event, hint) do
18
+ Sentry::Sanitizer::Cleaner.new(Sentry.configuration.sanitize).call(event)
30
19
 
31
- sanitize.fields = fields
32
- end
33
-
34
- def sanitize_http_headers(headers)
35
- unless headers.is_a? Array
36
- raise ArgumentError, 'sanitize_http_headers must be array'
20
+ event
37
21
  end
38
-
39
- sanitize.http_headers = headers
40
- end
41
-
42
- def sanitize_cookies(cookies)
43
- unless [TrueClass, FalseClass].include?(cookies.class)
44
- raise ArgumentError, 'sanitize_cookies must be boolean'
45
- end
46
-
47
- sanitize.cookies = cookies
48
- end
49
-
50
- add_post_initialization_callback do
51
- self.before_send = Sentry::Sanitizer::Cleaner::HOOK if sanitize.configured?
52
22
  end
53
23
  end
54
24
 
@@ -59,6 +29,30 @@ module Sentry
59
29
  def configured?
60
30
  [fields, http_headers, cookies].any? { |setting| !setting.nil? }
61
31
  end
32
+
33
+ def fields=(fields)
34
+ unless fields.is_a? Array
35
+ raise ArgumentError, 'sanitize_fields must be array'
36
+ end
37
+
38
+ @fields = fields
39
+ end
40
+
41
+ def http_headers=(headers)
42
+ unless [Array, TrueClass, FalseClass].include?(headers.class)
43
+ raise ArgumentError, 'sanitize_http_headers must be array'
44
+ end
45
+
46
+ @http_headers = headers
47
+ end
48
+
49
+ def cookies=(cookies)
50
+ unless [TrueClass, FalseClass].include?(cookies.class)
51
+ raise ArgumentError, 'sanitize_cookies must be boolean'
52
+ end
53
+
54
+ @cookies = cookies
55
+ end
62
56
  end
63
57
  end
64
58
  end
@@ -0,0 +1,25 @@
1
+ module Sentry
2
+ module Sanitizer
3
+ module ConfigurationMixin
4
+ # Allow adding multiple hooks for this extension
5
+ def before_send=(value)
6
+ unless value == false || value.respond_to?(:call)
7
+ raise ArgumentError, "before_send must be callable (or false to disable)"
8
+ end
9
+
10
+ return value if value == false
11
+
12
+ @before_send_hook_list ||= []
13
+ @before_send_hook_list << value
14
+
15
+ @before_send = ->(event, hint) {
16
+ @before_send_hook_list.each do |hook|
17
+ event = hook.call(event, hint)
18
+ end
19
+
20
+ event
21
+ }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Sanitizer
3
- VERSION = "0.1.0"
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -30,6 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'bundler', '>= 1.17'
31
31
  spec.add_development_dependency 'rake', '~> 10.0'
32
32
  spec.add_development_dependency 'rspec', '~> 3.0'
33
+ spec.add_development_dependency 'rack'
34
+ spec.add_development_dependency 'pry-byebug'
33
35
 
34
36
  spec.add_runtime_dependency 'sentry-ruby', '~> 4.2.0'
35
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-sanitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentine Kiselev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-05 00:00:00.000000000 Z
11
+ date: 2021-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack
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: pry-byebug
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'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: sentry-ruby
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -77,6 +105,7 @@ files:
77
105
  - ".rspec"
78
106
  - ".travis.yml"
79
107
  - Gemfile
108
+ - Gemfile.lock
80
109
  - LICENSE.txt
81
110
  - README.md
82
111
  - Rakefile
@@ -86,6 +115,7 @@ files:
86
115
  - lib/sentry/sanitizer.rb
87
116
  - lib/sentry/sanitizer/cleaner.rb
88
117
  - lib/sentry/sanitizer/configuration.rb
118
+ - lib/sentry/sanitizer/configuration_mixin.rb
89
119
  - lib/sentry/sanitizer/version.rb
90
120
  - sentry-sanitizer.gemspec
91
121
  homepage: https://github.com/mrexox/sentry-sanitizer