rails-profiler 0.44.14 → 0.44.16
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 +21 -0
- data/lib/profiler/collectors/log_collector.rb +3 -1
- data/lib/profiler/console_profiler.rb +1 -1
- data/lib/profiler/job_profiler.rb +1 -1
- data/lib/profiler/middleware/profiler_middleware.rb +20 -2
- data/lib/profiler/models/profile.rb +5 -4
- data/lib/profiler/replay.rb +35 -11
- 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: 4c0e866574bd1980a2d0110b9cad69a60a2dc65e926f454cfeb1a90a90c54c44
|
|
4
|
+
data.tar.gz: ecfa5676aa6ef157d7cbfb2fdff269ef0475bc110f9296e8fc03ff90cba32965
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4681a333608b566a216560a2c9233754991fed624bc4d23f2a6e58b3524fb0a0d38730658230b10574b46e76781c2285a7f50cceeb0df13c22488bdb9b48734
|
|
7
|
+
data.tar.gz: 0cfbb5a92dcfa966dce9fc376e42c4223bf8523a1634ee7e7b5ddd367bf7e9768f4551177cf8d8c88393f2a79eacdf048666a64cc4eb7d0bcf1c9078e14e769e
|
data/CHANGELOG.md
CHANGED
|
@@ -19,6 +19,27 @@ every commit of every tag interval is accounted for one way or the other.
|
|
|
19
19
|
|
|
20
20
|
## [Unreleased]
|
|
21
21
|
|
|
22
|
+
## [0.44.16] - 2026-10-23
|
|
23
|
+
|
|
24
|
+
<!-- stamped -->
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- **LogCollector:** Prevent `BroadcastLogger` level from forcing `DEBUG` globally across all threads during profiling.
|
|
29
|
+
- **Middleware:** Skip toolbar injection for HTML downloads (`Content-Disposition: attachment`) and compressed responses (`Content-Encoding` present) to prevent file corruption.
|
|
30
|
+
- **Middleware:** Remove `ETag` and `Last-Modified` headers when toolbar is injected to prevent stale cached responses on 304 Not Modified.
|
|
31
|
+
- **Profiler:** Catch `Exception` (not just `StandardError`) to properly handle `Interrupt`, `SignalException`, and `Sidekiq::Shutdown`, marking profiles as failed instead of completed.
|
|
32
|
+
|
|
33
|
+
## [0.44.15] - 2026-10-23
|
|
34
|
+
|
|
35
|
+
<!-- stamped -->
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
|
|
39
|
+
- **Replay:** Include `Content-Type` header from captured request when replaying. Previously, only `HTTP_*` Rack env vars were captured, missing `CONTENT_TYPE` which is stored separately. Replayed JSON POST requests were incorrectly treated as form data. Refs #64
|
|
40
|
+
- **Replay:** Reject stored request bodies containing redaction masks (`[FILTERED]` or `[FILTERED: ...]` markers) and note them in the result instead of sending them as real data, including when the captured params would otherwise have been re-encoded into a replacement body. Refs #64
|
|
41
|
+
- **Replay:** Validate that the `headers` override parameter is a Hash or nil; previously passing a string or other type caused `NoMethodError` resulting in a 500 error. Now raises `Replay::Invalid` with a clear message. Refs #64
|
|
42
|
+
|
|
22
43
|
## [0.44.14] - 2026-10-23
|
|
23
44
|
|
|
24
45
|
<!-- stamped -->
|
|
@@ -145,8 +145,10 @@ module Profiler
|
|
|
145
145
|
|
|
146
146
|
if defined?(Rails) && Rails.logger
|
|
147
147
|
if Rails.logger.respond_to?(:broadcast_to)
|
|
148
|
-
@capture_logger = CaptureLogger.new(@logs)
|
|
149
148
|
@broadcaster = Rails.logger
|
|
149
|
+
level = @broadcaster.level
|
|
150
|
+
@capture_logger = CaptureLogger.new(@logs)
|
|
151
|
+
@capture_logger.level = level
|
|
150
152
|
@broadcaster.broadcast_to(@capture_logger)
|
|
151
153
|
elsif defined?(ActiveSupport::Logger) && ActiveSupport::Logger.respond_to?(:broadcast)
|
|
152
154
|
self.class.attach_legacy_broadcast(Rails.logger)
|
|
@@ -136,11 +136,15 @@ module Profiler
|
|
|
136
136
|
|
|
137
137
|
set_header(headers, TOKEN_HEADER, profile.token)
|
|
138
138
|
|
|
139
|
-
if html_response?(headers)
|
|
139
|
+
if html_response?(headers) && !attachment_response?(headers) && !encoded_response?(headers)
|
|
140
140
|
nonce = env['action_dispatch.content_security_policy_nonce']
|
|
141
141
|
injected = ToolbarInjector.new(body, profile.token, nonce).inject
|
|
142
142
|
# A HEAD answer, or a page without </body>, keeps the length it announced.
|
|
143
|
-
|
|
143
|
+
unless injected.equal?(body)
|
|
144
|
+
update_content_length(headers, injected)
|
|
145
|
+
delete_header(headers, "ETag")
|
|
146
|
+
delete_header(headers, "Last-Modified")
|
|
147
|
+
end
|
|
144
148
|
body = injected
|
|
145
149
|
end
|
|
146
150
|
|
|
@@ -346,6 +350,15 @@ module Profiler
|
|
|
346
350
|
content_type(headers).include?("text/html")
|
|
347
351
|
end
|
|
348
352
|
|
|
353
|
+
def attachment_response?(headers)
|
|
354
|
+
disposition = header(headers, "content-disposition")
|
|
355
|
+
disposition&.split(";", 2)&.first&.strip&.casecmp?("attachment")
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
def encoded_response?(headers)
|
|
359
|
+
header(headers, "content-encoding").present?
|
|
360
|
+
end
|
|
361
|
+
|
|
349
362
|
def content_type(headers)
|
|
350
363
|
header(headers, "content-type").to_s
|
|
351
364
|
end
|
|
@@ -368,6 +381,11 @@ module Profiler
|
|
|
368
381
|
headers[existing.first || name] = value
|
|
369
382
|
end
|
|
370
383
|
|
|
384
|
+
def delete_header(headers, name)
|
|
385
|
+
existing = headers.keys.select { |key| key.to_s.casecmp?(name) }
|
|
386
|
+
existing.each { |key| headers.delete(key) }
|
|
387
|
+
end
|
|
388
|
+
|
|
371
389
|
# Only a length the application announced is corrected: a chunked or unsized answer
|
|
372
390
|
# stays without one.
|
|
373
391
|
def update_content_length(headers, body)
|
|
@@ -428,10 +428,11 @@ module Profiler
|
|
|
428
428
|
end
|
|
429
429
|
|
|
430
430
|
def extract_headers(env)
|
|
431
|
-
env.select { |k, _| k.start_with?("HTTP_") }
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
431
|
+
headers = env.select { |k, _| k.start_with?("HTTP_") }
|
|
432
|
+
.transform_keys { |k| k.sub(/^HTTP_/, "").split("_").map(&:capitalize).join("-") }
|
|
433
|
+
headers["Content-Type"] = env["CONTENT_TYPE"] if env["CONTENT_TYPE"]
|
|
434
|
+
headers.select { |k, _| ALLOWED_HEADERS.include?(k) }
|
|
435
|
+
.then { |h| Redaction.filter_headers(h) }
|
|
435
436
|
end
|
|
436
437
|
end
|
|
437
438
|
end
|
data/lib/profiler/replay.rb
CHANGED
|
@@ -242,8 +242,11 @@ module Profiler
|
|
|
242
242
|
end
|
|
243
243
|
notes << "Not sent, masked in the profile: #{redacted.join(", ")}." unless redacted.empty?
|
|
244
244
|
|
|
245
|
+
override_headers = options[:headers]
|
|
246
|
+
raise Invalid, "headers must be a Hash or nil" unless override_headers.nil? || override_headers.is_a?(Hash)
|
|
247
|
+
|
|
245
248
|
ignored = []
|
|
246
|
-
(
|
|
249
|
+
(override_headers || {}).each do |name, value|
|
|
247
250
|
if FORBIDDEN_HEADERS.include?(name.to_s.downcase) || name.to_s.match?(/[\r\n:\s]/) || value.to_s.match?(/[\r\n]/)
|
|
248
251
|
ignored << name.to_s
|
|
249
252
|
next
|
|
@@ -268,22 +271,32 @@ module Profiler
|
|
|
268
271
|
end
|
|
269
272
|
|
|
270
273
|
def body_and_query(source, options, method, path_query, headers, notes)
|
|
274
|
+
raise Invalid, "params must be a Hash or nil" if options.key?(:params) && !options[:params].nil? && !options[:params].is_a?(Hash)
|
|
275
|
+
raise Invalid, "body must be a String or nil" if options.key?(:body) && !options[:body].nil? && !options[:body].is_a?(String)
|
|
276
|
+
|
|
271
277
|
params = options.key?(:params) ? options[:params] : default_params(source, notes)
|
|
272
278
|
query = options.key?(:query) ? encode_query(options[:query]) : path_query
|
|
273
279
|
body = nil
|
|
274
280
|
|
|
281
|
+
masked_body_dropped = false
|
|
275
282
|
if options.key?(:body)
|
|
276
283
|
body = options[:body].to_s
|
|
277
|
-
elsif !options.key?(:params) && !BODYLESS_METHODS.include?(method)
|
|
278
|
-
body =
|
|
284
|
+
elsif !options.key?(:params) && !BODYLESS_METHODS.include?(method)
|
|
285
|
+
body, masked_body_dropped = stored_body(source, notes)
|
|
279
286
|
end
|
|
280
287
|
|
|
281
|
-
|
|
288
|
+
# A body dropped for masking must not be silently replaced by one rebuilt from params:
|
|
289
|
+
# the note says it "was not sent", not "was sent after all, reconstructed differently".
|
|
290
|
+
if !masked_body_dropped && params.is_a?(Hash) && !params.empty? && !options.key?(:query) && path_query.nil? && body.nil?
|
|
282
291
|
if BODYLESS_METHODS.include?(method)
|
|
283
292
|
query = encode_query(params)
|
|
284
293
|
else
|
|
285
294
|
body, content_type = encode_params_body(params, headers)
|
|
286
|
-
headers
|
|
295
|
+
user_content_type = (options[:headers] || {}).any? { |name, _| name.to_s.casecmp?("Content-Type") }
|
|
296
|
+
unless user_content_type
|
|
297
|
+
headers.delete_if { |existing, _| existing.casecmp?("Content-Type") }
|
|
298
|
+
headers["Content-Type"] = content_type
|
|
299
|
+
end
|
|
287
300
|
end
|
|
288
301
|
end
|
|
289
302
|
|
|
@@ -300,19 +313,30 @@ module Profiler
|
|
|
300
313
|
params.reject { |_, value| value == Redaction::MASK }
|
|
301
314
|
end
|
|
302
315
|
|
|
316
|
+
# Returns [body, masked]: masked is true only when a body existed and was dropped because
|
|
317
|
+
# it contains a redaction marker, so the caller can tell that case apart from "no body was
|
|
318
|
+
# ever captured", for which the default_params fallback remains appropriate.
|
|
303
319
|
def stored_body(source, notes)
|
|
304
|
-
return nil if source.request_body.nil? || source.request_body.empty?
|
|
320
|
+
return [nil, false] if source.request_body.nil? || source.request_body.empty?
|
|
305
321
|
|
|
306
322
|
if source.request_body_truncated
|
|
307
323
|
notes << "The stored request body is truncated (max_captured_body_bytes): the replay sends what was kept."
|
|
308
324
|
end
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
325
|
+
|
|
326
|
+
decoded = if source.request_body_encoding == "base64"
|
|
327
|
+
Base64.strict_decode64(source.request_body)
|
|
328
|
+
else
|
|
329
|
+
Models::Profile.decode_body(source.request_body, source.request_body_encoding).first
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
if decoded.include?(Redaction::MASK) || decoded.include?("[FILTERED:")
|
|
333
|
+
notes << "The stored request body contains masked values and was not sent."
|
|
334
|
+
return [nil, true]
|
|
313
335
|
end
|
|
336
|
+
|
|
337
|
+
[decoded, false]
|
|
314
338
|
rescue ArgumentError
|
|
315
|
-
nil
|
|
339
|
+
[nil, false]
|
|
316
340
|
end
|
|
317
341
|
|
|
318
342
|
def encode_query(value)
|
data/lib/profiler/version.rb
CHANGED