rails-profiler 0.44.14 → 0.44.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f304a45c85e9192bf75e9310c5226587d922efcde7c5b0e8556bc9806b44814c
4
- data.tar.gz: bd8ae9a3a92bbea50328f57f17fd7ca2b7307929230ed70a1913d66c268a508e
3
+ metadata.gz: 5494040c10e8c5e51c20aacf54788fdab573a5814f394ced5c7c7f7caa4693aa
4
+ data.tar.gz: b84ed786eaed7a1f59ed8ee9b953a546be714432dbecd7ad372fee2b4446d567
5
5
  SHA512:
6
- metadata.gz: bc552f921859972a5160aa7d8615e6ce9f725e71e2ef22e59d4ac804f598e77cfb69f908b0f8c9f86219c5d6e5bc2095b9ad4c3fc4e39f247c4a777c21a847cf
7
- data.tar.gz: 131fea7f68ec9cb7abe63b6d9f426752bdcc22676ca8e7315bed758dc9097a007ebbfa0fc6e42f8b62a70ae21a98037be514bd9a30fd4ccf9cb7afa432fcbaca
6
+ metadata.gz: 4a40f0b6d4d6c79de401838152198aae9528b795061f96c991e7a4bc1c65d8881af8f489d71f8e02078ee110a0de49b3d6715b82f818e00643fbbb67c9e84975
7
+ data.tar.gz: 8b49e505d5a86c01debb8fed088e3e428ff1e28b1492009f8a86c655c70d258b0f323d394fee3a3d2fac49ab2369ba4a14e1a106f7e2a651ebdf22cb14c37222
data/CHANGELOG.md CHANGED
@@ -19,6 +19,16 @@ every commit of every tag interval is accounted for one way or the other.
19
19
 
20
20
  ## [Unreleased]
21
21
 
22
+ ## [0.44.15] - 2026-10-23
23
+
24
+ <!-- stamped -->
25
+
26
+ ### Fixed
27
+
28
+ - **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
29
+ - **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
30
+ - **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
31
+
22
32
  ## [0.44.14] - 2026-10-23
23
33
 
24
34
  <!-- stamped -->
@@ -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
- .transform_keys { |k| k.sub(/^HTTP_/, "").split("_").map(&:capitalize).join("-") }
433
- .select { |k, _| ALLOWED_HEADERS.include?(k) }
434
- .then { |headers| Redaction.filter_headers(headers) }
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
@@ -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
- (options[:headers] || {}).each do |name, value|
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) && (stored = stored_body(source, notes))
278
- body = stored
284
+ elsif !options.key?(:params) && !BODYLESS_METHODS.include?(method)
285
+ body, masked_body_dropped = stored_body(source, notes)
279
286
  end
280
287
 
281
- if params.is_a?(Hash) && !params.empty? && !options.key?(:query) && path_query.nil? && body.nil?
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["Content-Type"] ||= content_type
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
- if source.request_body_encoding == "base64"
310
- Base64.strict_decode64(source.request_body)
311
- else
312
- Models::Profile.decode_body(source.request_body, source.request_body_encoding).first
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)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Profiler
4
- VERSION = "0.44.14"
4
+ VERSION = "0.44.15"
5
5
 
6
6
  GEM_ROOT = File.expand_path("../..", __dir__)
7
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.44.14
4
+ version: 0.44.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Duplessy