logtail-rack 0.2.1 → 0.2.3

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: 73931379e41a5b92e72919963376a2f6b6b8ec06871b9a410bc6c8339228387d
4
- data.tar.gz: 01b32fd44ea670b47d5d7340a8c02c1305b203332f298818dff9ec68058e79e2
3
+ metadata.gz: 43f0b7693831d0097e1496ba79258afc7b8b7cda69d805fa99248cbc79812181
4
+ data.tar.gz: 23bdde6dc4a16420b3f8604edc3266775b248e2a51177be01c64a314577612d9
5
5
  SHA512:
6
- metadata.gz: 02f9dcd2e699b1c52d9f31265bb1f77f057c8e63bab5d2e87475e7b22823a16723ef3b69e5cd99827b1d9bdf0a27db35ba7f7c3a1b7656e099a60171a0c1476d
7
- data.tar.gz: 4e2a9cbb7b647f1ef6574ecea49db83616e7ea9082dec902c5bba980aaebc14a5cefa325ade3ed3a4d3085aba2c07610f8469b362560f94a5ef3bea6248e77f4
6
+ metadata.gz: f9dc63f41ea21c4f31360608d82ec1cbf6652cac1774a28695a845a36858a95215ee24d49696278f07267266922659559cee8790a85767e64cd143e833232950
7
+ data.tar.gz: c1faf9719cac776039dac04d3acc9b91b9520f9f7983a4db242344e9f66cfedd37feb0bfe8b6575185b883918e45b37eaf76a61708f364dd627a8805349f6989
@@ -23,7 +23,6 @@ jobs:
23
23
  - 2.5
24
24
  - 2.4
25
25
  - 2.3
26
- - 2.2
27
26
  - jruby-9.4.3.0
28
27
  - jruby-9.2.14.0
29
28
  - truffleruby-23.0.0
@@ -1,6 +1,7 @@
1
1
  require "logtail/contexts/http"
2
2
  require "logtail/current_context"
3
3
  require "logtail-rack/middleware"
4
+ require "logtail-rack/util/encoding"
4
5
  require "logtail-rack/util/request"
5
6
 
6
7
  module Logtail
@@ -11,10 +12,10 @@ module Logtail
11
12
  def call(env)
12
13
  request = Util::Request.new(env)
13
14
  context = Contexts::HTTP.new(
14
- host: request.host.force_encoding('UTF-8'),
15
- method: request.request_method.force_encoding('UTF-8'),
15
+ host: Util::Encoding.force_utf8_encoding(request),
16
+ method: Util::Encoding.force_utf8_encoding(request.request_method),
16
17
  path: request.path,
17
- remote_addr: request.ip.force_encoding('UTF-8'),
18
+ remote_addr: Util::Encoding.force_utf8_encoding(request.ip),
18
19
  request_id: request.request_id
19
20
  )
20
21
 
@@ -6,6 +6,7 @@ require "logtail/current_context"
6
6
  require "logtail-rack/http_request"
7
7
  require "logtail-rack/http_response"
8
8
  require "logtail-rack/middleware"
9
+ require "logtail-rack/util/encoding"
9
10
 
10
11
  module Logtail
11
12
  module Integrations
@@ -102,23 +103,24 @@ module Logtail
102
103
  @silence_request
103
104
  end
104
105
 
105
- def http_body_limit=(value)
106
- @http_body_limit = value
107
- end
108
-
109
- # Accessor method for {#http_body_limit=}
110
- def http_body_limit
111
- @http_body_limit
112
- end
113
-
106
+ # Filter sensitive HTTP headers (such as "Authorization: Bearer secret_token")
107
+ #
108
+ # Filtered HTTP header values will be sent to Better Stack as "[FILTERED]"
109
+ #
110
+ # @example
111
+ # Logtail::Integrations::Rack::HTTPEvents.http_header_filters = ["Authorization"]
114
112
  def http_header_filters=(value)
115
- @http_header_filters = value
113
+ @http_header_filters = value.map { |header_name| normalize_header_name(header_name) }
116
114
  end
117
115
 
118
116
  # Accessor method for {#http_header_filters=}
119
117
  def http_header_filters
120
118
  @http_header_filters
121
119
  end
120
+
121
+ def normalize_header_name(name)
122
+ name.to_s.downcase.gsub("-", "_")
123
+ end
122
124
  end
123
125
 
124
126
  CONTENT_LENGTH_KEY = 'Content-Length'.freeze
@@ -147,13 +149,11 @@ module Logtail
147
149
 
148
150
  http_response = HTTPResponse.new(
149
151
  content_length: content_length,
150
- headers: headers,
152
+ headers: filter_http_headers(headers),
151
153
  http_context: http_context,
152
154
  request_id: request.request_id,
153
155
  status: status,
154
156
  duration_ms: duration_ms,
155
- body_limit: self.class.http_body_limit,
156
- headers_to_sanitize: self.class.http_header_filters,
157
157
  )
158
158
 
159
159
  {
@@ -179,16 +179,14 @@ module Logtail
179
179
  http_request = HTTPRequest.new(
180
180
  body: event_body,
181
181
  content_length: safe_to_i(request.content_length),
182
- headers: request.headers,
183
- host: force_encoding(request.host),
182
+ headers: filter_http_headers(request.headers),
183
+ host: Util::Encoding.force_utf8_encoding(request.host),
184
184
  method: request.request_method,
185
185
  path: request.path,
186
186
  port: request.port,
187
- query_string: force_encoding(request.query_string),
187
+ query_string: Util::Encoding.force_utf8_encoding(request.query_string),
188
188
  request_id: request.request_id,
189
- scheme: force_encoding(request.scheme),
190
- body_limit: self.class.http_body_limit,
191
- headers_to_sanitize: self.class.http_header_filters,
189
+ scheme: Util::Encoding.force_utf8_encoding(request.scheme),
192
190
  )
193
191
 
194
192
  {
@@ -223,12 +221,10 @@ module Logtail
223
221
  http_response = HTTPResponse.new(
224
222
  body: event_body,
225
223
  content_length: content_length,
226
- headers: headers,
224
+ headers: filter_http_headers(headers),
227
225
  request_id: request.request_id,
228
226
  status: status,
229
227
  duration_ms: duration_ms,
230
- body_limit: self.class.http_body_limit,
231
- headers_to_sanitize: self.class.http_header_filters,
232
228
  )
233
229
 
234
230
  {
@@ -272,16 +268,15 @@ module Logtail
272
268
  end
273
269
  end
274
270
 
275
- def safe_to_i(val)
276
- val.nil? ? nil : val.to_i
271
+ def filter_http_headers(headers)
272
+ headers.each do |name, _|
273
+ normalized_header_name = self.class.normalize_header_name(name)
274
+ headers[name] = "[FILTERED]" if self.class.http_header_filters&.include?(normalized_header_name)
275
+ end
277
276
  end
278
277
 
279
- def force_encoding(value)
280
- if value.respond_to?(:force_encoding)
281
- value.dup.force_encoding('UTF-8')
282
- else
283
- value
284
- end
278
+ def safe_to_i(val)
279
+ val.nil? ? nil : val.to_i
285
280
  end
286
281
  end
287
282
  end
@@ -3,7 +3,10 @@ module Logtail
3
3
  class Encoding
4
4
  def self.force_utf8_encoding(data)
5
5
  if data.respond_to?(:force_encoding)
6
- data.dup.force_encoding('UTF-8')
6
+ encoded_data = data.dup.force_encoding('UTF-8')
7
+ encoded_data = data.dup.force_encoding("ISO-8859-1").encode("UTF-8") unless encoded_data.valid_encoding?
8
+ encoded_data = data.dup.encode('UTF-8', invalid: :replace, undef: :replace) unless encoded_data.valid_encoding?
9
+ encoded_data
7
10
  elsif data.respond_to?(:transform_values)
8
11
  data.transform_values { |val| Logtail::Util::Encoding.force_utf8_encoding(val) }
9
12
  else
@@ -1,7 +1,7 @@
1
1
  module Logtail
2
2
  module Integrations
3
3
  module Rack
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.3"
5
5
  end
6
6
  end
7
7
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = "https://github.com/logtail/logtail-ruby-rack"
13
13
  spec.license = "ISC"
14
14
 
15
- spec.required_ruby_version = '>= 2.2.10'
15
+ spec.required_ruby_version = '>= 2.3'
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = "https://github.com/logtail/logtail-ruby-rack"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logtail-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logtail
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-04 00:00:00.000000000 Z
11
+ date: 2023-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logtail
@@ -129,14 +129,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
129
  requirements:
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: 2.2.10
132
+ version: '2.3'
133
133
  required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - ">="
136
136
  - !ruby/object:Gem::Version
137
137
  version: '0'
138
138
  requirements: []
139
- rubygems_version: 3.3.7
139
+ rubygems_version: 3.3.3
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Logtail integration for Rack