rails-profiler 0.45.3 → 0.45.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/profiler/middleware/capturing_body.rb +2 -3
- data/lib/profiler/middleware/profiler_middleware.rb +2 -6
- data/lib/profiler/models/profile.rb +28 -10
- data/lib/profiler/redaction.rb +10 -0
- data/lib/profiler/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9b4332eee9a830876c3ffe5c137d94543461a2ad84f05e9c32943c8aac2ed8a1
|
|
4
|
+
data.tar.gz: b004d3659cf24ddddae10cbdc416922ccf827ece582b1681417b456c1037d96c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea60c6cfdac1a5be97ea9c4b7f7e12b6968ada0b0a1e3d7df5edead621cd2b43fa567b69b217351ac46df0af149c772a98591e4b24f84586d9c677f748422ab7
|
|
7
|
+
data.tar.gz: 995ee37e14b80fca5949f3a49c2ee11fedf0a08e992b0c37435b83c6fea24c4e6193b3971a93df125288f681897e630f5e7ae06a940f4413c9592d9e4825a6fa
|
data/CHANGELOG.md
CHANGED
|
@@ -19,6 +19,14 @@ every commit of every tag interval is accounted for one way or the other.
|
|
|
19
19
|
|
|
20
20
|
## [Unreleased]
|
|
21
21
|
|
|
22
|
+
## [0.45.4] - 2026-10-27
|
|
23
|
+
|
|
24
|
+
<!-- stamped -->
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- A JSON, NDJSON or form request or response body longer than `max_captured_body_bytes` is no longer masked as `[FILTERED: unparseable ...]` in a profile captured by the Rack middleware. The body is redacted whole, then cut, as Net::HTTP bodies already are.
|
|
29
|
+
|
|
22
30
|
## [0.45.3] - 2026-10-27
|
|
23
31
|
|
|
24
32
|
<!-- stamped -->
|
|
@@ -98,14 +98,13 @@ module Profiler
|
|
|
98
98
|
chunk = chunk.to_s
|
|
99
99
|
@encoding ||= chunk.encoding
|
|
100
100
|
@size += chunk.bytesize
|
|
101
|
-
# One byte past the limit, so that
|
|
101
|
+
# One byte past the limit, so that the profile knows the body goes on.
|
|
102
102
|
room = @limit ? @limit + 1 - @captured.bytesize : chunk.bytesize
|
|
103
103
|
@captured << chunk.byteslice(0, room).b if room.positive?
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
def captured
|
|
107
|
-
|
|
108
|
-
@limit ? Redaction.cut_bytes(text, @limit) : text
|
|
107
|
+
@captured.dup.force_encoding(@encoding || Encoding::UTF_8)
|
|
109
108
|
end
|
|
110
109
|
end
|
|
111
110
|
end
|
|
@@ -194,7 +194,7 @@ module Profiler
|
|
|
194
194
|
finish_streamed(env, streamed, collectors, request_body, allocations_before, status, profiled_headers,
|
|
195
195
|
captured, size, complete, error)
|
|
196
196
|
end
|
|
197
|
-
limit = Profiler.configuration.max_captured_body_bytes
|
|
197
|
+
limit = Redaction.capture_limit(Profiler.configuration.max_captured_body_bytes, content_type(headers))
|
|
198
198
|
streamed.body = CapturingBody.new(body, limit: limit, context: streamed) do |captured, size, complete, error|
|
|
199
199
|
streamed.finish(captured, size, complete, error)
|
|
200
200
|
end
|
|
@@ -248,9 +248,6 @@ module Profiler
|
|
|
248
248
|
|
|
249
249
|
# +complete+: whether +size+ is the whole body's, or only what was seen before it stopped.
|
|
250
250
|
def record_response(env, profile, request_body, status, headers, content, size, complete)
|
|
251
|
-
limit = Profiler.configuration.max_captured_body_bytes
|
|
252
|
-
content = Redaction.cut_bytes(content, limit) if limit
|
|
253
|
-
|
|
254
251
|
profile.finish(status, headers)
|
|
255
252
|
profile.set_bodies(
|
|
256
253
|
request_body: request_body[:content],
|
|
@@ -475,7 +472,7 @@ module Profiler
|
|
|
475
472
|
input = env["rack.input"]
|
|
476
473
|
return { content: "", size: nil } unless input.respond_to?(:rewind)
|
|
477
474
|
|
|
478
|
-
limit = Profiler.configuration.max_captured_body_bytes
|
|
475
|
+
limit = Redaction.capture_limit(Profiler.configuration.max_captured_body_bytes, env["CONTENT_TYPE"])
|
|
479
476
|
begin
|
|
480
477
|
input.rewind
|
|
481
478
|
content = (limit ? input.read(limit + 1) : input.read).to_s
|
|
@@ -488,7 +485,6 @@ module Profiler
|
|
|
488
485
|
# Without a Content-Length, the size of a cut body is only known to exceed the limit.
|
|
489
486
|
size = known ? declared.to_i : content.bytesize
|
|
490
487
|
size_is_minimum = !known && limit && content.bytesize > limit
|
|
491
|
-
content = Redaction.cut_bytes(content, limit) if limit
|
|
492
488
|
{ content: content, size: size, size_is_minimum: size_is_minimum || false }
|
|
493
489
|
rescue => e
|
|
494
490
|
Profiler.log_error("ProfilerMiddleware: could not read the request body", e)
|
|
@@ -58,14 +58,15 @@ module Profiler
|
|
|
58
58
|
def set_bodies(request_body:, response_body:, req_content_type:, resp_content_type:,
|
|
59
59
|
request_body_size: nil, response_body_size: nil,
|
|
60
60
|
request_body_size_is_minimum: false, response_body_size_is_minimum: false)
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
limit = Profiler.configuration.max_captured_body_bytes
|
|
62
|
+
req = process_body(request_body, req_content_type, limit, body_whole_size(request_body, request_body_size, request_body_size_is_minimum, limit))
|
|
63
|
+
resp = process_body(response_body, resp_content_type, limit, body_whole_size(response_body, response_body_size, response_body_size_is_minimum, limit))
|
|
63
64
|
@request_body = req[:body]
|
|
64
65
|
@request_body_encoding = req[:encoding]
|
|
65
66
|
@response_body = resp[:body]
|
|
66
67
|
@response_body_encoding = resp[:encoding]
|
|
67
|
-
@request_body_size, @request_body_truncated = body_size(request_body, request_body_size)
|
|
68
|
-
@response_body_size, @response_body_truncated = body_size(response_body, response_body_size)
|
|
68
|
+
@request_body_size, @request_body_truncated = body_size(request_body, request_body_size, limit)
|
|
69
|
+
@response_body_size, @response_body_truncated = body_size(response_body, response_body_size, limit)
|
|
69
70
|
@request_body_size_is_minimum = request_body_size_is_minimum ? true : false
|
|
70
71
|
@response_body_size_is_minimum = response_body_size_is_minimum ? true : false
|
|
71
72
|
end
|
|
@@ -268,15 +269,22 @@ module Profiler
|
|
|
268
269
|
|
|
269
270
|
private
|
|
270
271
|
|
|
271
|
-
|
|
272
|
+
# +limit+ is max_captured_body_bytes: a body longer than it is redacted whole and the result
|
|
273
|
+
# cut (Redaction.filter_truncated_body), so a cut JSON text is never what the filter sees.
|
|
274
|
+
# +size+ is the length of the whole body, to tell a body held whole from a beginning.
|
|
275
|
+
def process_body(raw, content_type, limit = nil, size = nil)
|
|
272
276
|
return { body: nil, encoding: "text" } if raw.nil? || raw.empty?
|
|
273
277
|
|
|
274
278
|
if BodyContent.binary?(raw, content_type)
|
|
275
279
|
# Masked on the raw bytes, before the encoding hides them from any later search. A
|
|
276
|
-
# compressed format (zip, png, gzip...) does not hold the secret as it is
|
|
277
|
-
|
|
280
|
+
# compressed format (zip, png, gzip...) does not hold the secret as it is, and a
|
|
281
|
+
# credential cut in two would escape the masking, hence the cut after it.
|
|
282
|
+
masked = Redaction.hide_credentials(raw.b)
|
|
283
|
+
masked = Redaction.cut_bytes(masked, limit) if limit
|
|
284
|
+
{ body: Base64.strict_encode64(masked), encoding: "base64" }
|
|
278
285
|
else
|
|
279
|
-
|
|
286
|
+
filtered = limit ? Redaction.filter_truncated_body(raw, content_type, limit, size) : Redaction.filter_body(raw, content_type)
|
|
287
|
+
text = utf8_text(filtered, content_type)
|
|
280
288
|
if compress_body?(text)
|
|
281
289
|
# The fastest level: paid on the request, a quarter larger than the default level.
|
|
282
290
|
{ body: Base64.strict_encode64(Zlib::Deflate.deflate(text, Zlib::BEST_SPEED)), encoding: "gzip+base64" }
|
|
@@ -319,12 +327,22 @@ module Profiler
|
|
|
319
327
|
end
|
|
320
328
|
end
|
|
321
329
|
|
|
322
|
-
def body_size(captured, total)
|
|
330
|
+
def body_size(captured, total, limit = nil)
|
|
323
331
|
captured_size = captured.to_s.bytesize
|
|
324
|
-
|
|
332
|
+
captured_size = limit if limit && captured_size > limit
|
|
333
|
+
total ||= captured.to_s.bytesize
|
|
325
334
|
[total, total > captured_size]
|
|
326
335
|
end
|
|
327
336
|
|
|
337
|
+
# The length of the whole body as far as it is known; one more than what was seen when
|
|
338
|
+
# the total is only a minimum and the body is longer than the limit, so that it counts as a beginning.
|
|
339
|
+
def body_whole_size(captured, total, minimum, limit)
|
|
340
|
+
seen = captured.to_s.bytesize
|
|
341
|
+
return seen + 1 if minimum && limit && seen > limit
|
|
342
|
+
|
|
343
|
+
total || seen
|
|
344
|
+
end
|
|
345
|
+
|
|
328
346
|
def compress_body?(text)
|
|
329
347
|
Profiler.configuration.compress_bodies &&
|
|
330
348
|
text.bytesize > Profiler.configuration.compress_body_threshold
|
data/lib/profiler/redaction.rb
CHANGED
|
@@ -255,6 +255,16 @@ module Profiler
|
|
|
255
255
|
"[FILTERED: truncated body that could not be filtered, #{raw.bytesize} bytes]"
|
|
256
256
|
end
|
|
257
257
|
|
|
258
|
+
# How many bytes of a body to copy so that it can be redacted whole before it is cut: a JSON,
|
|
259
|
+
# NDJSON or form body is copied up to MAX_REDACTABLE_BODY_BYTES, any other type (and a nil
|
|
260
|
+
# limit) up to +limit+.
|
|
261
|
+
def capture_limit(limit, content_type)
|
|
262
|
+
return limit if limit.nil? || limit >= MAX_REDACTABLE_BODY_BYTES
|
|
263
|
+
|
|
264
|
+
mime = content_type.to_s.split(";").first.to_s.strip.downcase
|
|
265
|
+
structured_type?(mime) ? MAX_REDACTABLE_BODY_BYTES : limit
|
|
266
|
+
end
|
|
267
|
+
|
|
258
268
|
# Masks the filtered values of a query string, pair by pair, leaving the
|
|
259
269
|
# rest of the string exactly as it was.
|
|
260
270
|
def filter_query(query)
|
data/lib/profiler/version.rb
CHANGED