rails-profiler 0.44.22 → 0.44.25
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 +30 -0
- data/lib/profiler/cluster/security.rb +9 -1
- data/lib/profiler/configuration.rb +6 -2
- data/lib/profiler/env_key_policy.rb +2 -1
- data/lib/profiler/local_request.rb +6 -0
- data/lib/profiler/mcp/server.rb +2 -1
- data/lib/profiler/mcp/tools/get_profile_detail.rb +4 -3
- data/lib/profiler/mcp/tools/get_profile_http.rb +5 -4
- data/lib/profiler/middleware/cors_policy.rb +22 -0
- data/lib/profiler/peers.rb +1 -0
- data/lib/profiler/railtie.rb +7 -0
- data/lib/profiler/redaction.rb +10 -6
- data/lib/profiler/tasks/profiler.rake +1 -1
- data/lib/profiler/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9ae9fe0ef9322cba9bf1ae8364bae2cfec9eb1ad3f11010351aa49180fcf2d89
|
|
4
|
+
data.tar.gz: 5cad7f44d5d1b0871a1379ffc1f95f13646a387dbf6146720c519d33a15b1752
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fb37b782a7e5e6fd12d77583dc625037baefb66195d6a59a7242945b0944f48d8d2f10d0cff1057cb4855ef6f4fb83773ac8c3cc00b4d8f6b4c96bb295d0f1e6
|
|
7
|
+
data.tar.gz: 0fde3a7cb33a929fd11caf3c93efb449db493c5e06609f46cf151a5ff7eb6a984823700614850dc9d02aa289cfd208a7ed971e97c80f10a2a8f2adb6388dc14f
|
data/CHANGELOG.md
CHANGED
|
@@ -19,6 +19,36 @@ every commit of every tag interval is accounted for one way or the other.
|
|
|
19
19
|
|
|
20
20
|
## [Unreleased]
|
|
21
21
|
|
|
22
|
+
## [0.44.25] - 2026-10-26
|
|
23
|
+
|
|
24
|
+
<!-- stamped -->
|
|
25
|
+
|
|
26
|
+
### Security
|
|
27
|
+
|
|
28
|
+
- **Authorization:** under `authorization_mode = :allow_authorized`, the `host=` parameter of the `Forwarded` header (RFC 7239) is now checked against the allowed hosts like `Host` and `X-Forwarded-Host`, closing a DNS rebinding bypass through that header.
|
|
29
|
+
|
|
30
|
+
## [0.44.24] - 2026-10-26
|
|
31
|
+
|
|
32
|
+
<!-- stamped -->
|
|
33
|
+
|
|
34
|
+
### Security
|
|
35
|
+
|
|
36
|
+
- **Secrets:** Refuse cluster secrets and peer tokens surrounded by spaces or newlines at boot, which break HTTP requests. `trailing` newlines cause `ArgumentError` in `Net::HTTP` and trailing spaces cause systematic 403 errors. Refs #74
|
|
37
|
+
- **Redaction:** Mask `peer_token` by value in captured data (headers, bodies, params) alongside `cluster_secret`, preventing credential leakage across profiles and logs. Refs #74. A secret or token padded with spaces stays masked.
|
|
38
|
+
- **Secrets:** A padded `cluster_secret` stays required (still refused) when `cluster_require_secret = false`, instead of silently disabling authentication. Refs #74
|
|
39
|
+
- **Environment:** Protect additional environment variables from override via the Env tab and MCP tools: `LOCALDOMAIN`, `RES_OPTIONS`, `HOSTALIASES`, `NODE_EXTRA_CA_CERTS` and `TMPDIR`. These variables control hostname resolution and certificate store location. Refs #74
|
|
40
|
+
- **CORS:** Warn at boot when `cors_allowed_origins` contains wildcard `"*"`, which allows any website to access the profiler if a visitor browses it. Recommend using specific origins instead. Refs #74
|
|
41
|
+
|
|
42
|
+
## [0.44.23] - 2026-10-25
|
|
43
|
+
|
|
44
|
+
<!-- stamped -->
|
|
45
|
+
|
|
46
|
+
### Fixed
|
|
47
|
+
|
|
48
|
+
- **MCP:** `get_profile` and `get_profile_http` tools no longer crash when rendering in-flight HTTP requests with `nil` duration, safely converting to 0.0ms for comparison and display, and a `nil` status is shown as an error.
|
|
49
|
+
- **Cluster:** `SlaveProxy#request` now catches `SocketError`, `SystemCallError`, `Net::OpenTimeout`, `Net::ReadTimeout`, `OpenSSL::SSL::SSLError` and `IOError` and re-raises a `Profiler::Error` naming the slave, so a tool reading from an unreachable slave gets a normal error response instead of an internal `json-rpc` failure (matching `Peers::PeerProxy#get_json`).
|
|
50
|
+
- **Tasks:** `rake profiler:mcp` now defaults to `:stdio` transport instead of configuration-dependent behavior, aligning with the documented interface; `MCP_TRANSPORT` environment variable still overrides.
|
|
51
|
+
|
|
22
52
|
## [0.44.22] - 2026-10-25
|
|
23
53
|
|
|
24
54
|
<!-- stamped -->
|
|
@@ -20,7 +20,14 @@ module Profiler
|
|
|
20
20
|
# and no cluster_secret, the behaviour of 0.30.6.
|
|
21
21
|
def secret_required?
|
|
22
22
|
config = Profiler.configuration
|
|
23
|
-
config.cluster_require_secret || configured_secret?
|
|
23
|
+
config.cluster_require_secret || configured_secret? || padded_secret?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# A secret that was meant to be set but is padded (a trailing newline from a file) stays
|
|
27
|
+
# required: dropping it would turn a configured secret into no authentication at all.
|
|
28
|
+
def padded_secret?
|
|
29
|
+
secret = Profiler.configuration.cluster_secret.to_s
|
|
30
|
+
!secret.strip.empty? && secret != secret.strip
|
|
24
31
|
end
|
|
25
32
|
|
|
26
33
|
def configured_secret?
|
|
@@ -31,6 +38,7 @@ module Profiler
|
|
|
31
38
|
def secret_problem
|
|
32
39
|
secret = Profiler.configuration.cluster_secret.to_s
|
|
33
40
|
return "No config.cluster_secret is configured" if secret.strip.empty?
|
|
41
|
+
return "config.cluster_secret is surrounded by spaces or newlines, which breaks HTTP requests" if secret != secret.strip
|
|
34
42
|
return nil if secret.strip.length >= MIN_SECRET_LENGTH
|
|
35
43
|
|
|
36
44
|
"config.cluster_secret is shorter than #{MIN_SECRET_LENGTH} characters, so it is ignored " \
|
|
@@ -511,8 +511,8 @@ module Profiler
|
|
|
511
511
|
"host name (#{e.message})"
|
|
512
512
|
end
|
|
513
513
|
|
|
514
|
-
# The DNS rebinding check for :allow_authorized: nil when the Host
|
|
515
|
-
#
|
|
514
|
+
# The DNS rebinding check for :allow_authorized: nil when the Host, X-Forwarded-Host and Forwarded host=
|
|
515
|
+
# values are allowed, otherwise a sentence naming the cause. A host is allowed when it is
|
|
516
516
|
# local, listed in config.hosts, or listed in config.mcp_allowed_hosts: the same rule the MCP
|
|
517
517
|
# HTTP transport already applies (Profiler::MCP::HttpGuard.allowed_host?), so a deployment
|
|
518
518
|
# that already lists its host for MCP does not have to list it twice.
|
|
@@ -532,6 +532,10 @@ module Profiler
|
|
|
532
532
|
return "the X-Forwarded-Host header #{remote.inspect} is not allowed: list it in config.hosts or " \
|
|
533
533
|
"config.mcp_allowed_hosts" if remote
|
|
534
534
|
|
|
535
|
+
forwarded = LocalRequest.forwarded_hosts(request).find { |h| !MCP::HttpGuard.allowed_host?(h, self) }
|
|
536
|
+
return "the Forwarded header host #{forwarded.inspect} is not allowed: list it in config.hosts or " \
|
|
537
|
+
"config.mcp_allowed_hosts" if forwarded
|
|
538
|
+
|
|
535
539
|
nil
|
|
536
540
|
end
|
|
537
541
|
|
|
@@ -21,7 +21,8 @@ module Profiler
|
|
|
21
21
|
# and which certificates it trusts, or the profiler's own read-only switch.
|
|
22
22
|
PROTECTED_KEYS = %w[
|
|
23
23
|
RAILS_ENV RACK_ENV DATABASE_URL SECRET_KEY_BASE RAILS_MASTER_KEY PROFILER_TEST_RUNNER_CHILD
|
|
24
|
-
PROFILER_MCP_READ_ONLY SSL_CERT_FILE SSL_CERT_DIR
|
|
24
|
+
PROFILER_MCP_READ_ONLY SSL_CERT_FILE SSL_CERT_DIR LOCALDOMAIN RES_OPTIONS HOSTALIASES
|
|
25
|
+
NODE_EXTRA_CA_CERTS TMPDIR
|
|
25
26
|
].freeze
|
|
26
27
|
# PG: libpq (PGHOST, PGPASSWORD, PGSERVICEFILE...). MYSQL_: the MySQL client (MYSQL_PWD,
|
|
27
28
|
# MYSQL_HOST...). OPENSSL_: OPENSSL_CONF and OPENSSL_MODULES can load a shared library.
|
|
@@ -104,6 +104,12 @@ module Profiler
|
|
|
104
104
|
allowed_host?(host_name(value))
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
+
# Hosts named by the host= parameter of a Forwarded header (RFC 7239), for callers that
|
|
108
|
+
# apply their own host policy (Configuration under :allow_authorized).
|
|
109
|
+
def forwarded_hosts(request)
|
|
110
|
+
forwarded_param(request.get_header("HTTP_FORWARDED").to_s, "host")
|
|
111
|
+
end
|
|
112
|
+
|
|
107
113
|
private
|
|
108
114
|
|
|
109
115
|
def host_denial_reason(request)
|
data/lib/profiler/mcp/server.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "mcp"
|
|
4
|
+
require "net/http"
|
|
4
5
|
require_relative "http_guard"
|
|
5
6
|
|
|
6
7
|
module Profiler
|
|
@@ -467,7 +468,7 @@ module Profiler
|
|
|
467
468
|
::MCP::Tool.define(name: name, description: description, input_schema: input_schema) do |server_context: nil, **args|
|
|
468
469
|
result = handler.call(args.transform_keys(&:to_s))
|
|
469
470
|
result.is_a?(::MCP::Tool::Response) ? result : ::MCP::Tool::Response.new(result)
|
|
470
|
-
rescue Profiler::Storage::Unavailable::Error, Profiler::Error => e
|
|
471
|
+
rescue Profiler::Storage::Unavailable::Error, Profiler::Error, SystemCallError, Net::OpenTimeout, Net::ReadTimeout => e
|
|
471
472
|
::MCP::Tool::Response.new([{ type: "text", text: e.message }], error: true)
|
|
472
473
|
end
|
|
473
474
|
end
|
|
@@ -400,9 +400,10 @@ module Profiler
|
|
|
400
400
|
if http_data["requests"] && !http_data["requests"].empty?
|
|
401
401
|
lines << "### Request List"
|
|
402
402
|
http_data["requests"].each_with_index do |req, index|
|
|
403
|
-
flag = req["duration"] >= threshold ? " [SLOW]" : ""
|
|
404
|
-
|
|
405
|
-
|
|
403
|
+
flag = (req["duration"] || 0).to_f >= threshold ? " [SLOW]" : ""
|
|
404
|
+
status = req["status"].to_i
|
|
405
|
+
err = status >= 400 || status == 0 ? " [ERROR]" : ""
|
|
406
|
+
lines << "\n**#{index + 1}. #{req['method']} #{req['url']}** - #{status == 0 ? 'error' : status} - #{(req['duration'] || 0).to_f.round(2)} ms#{flag}#{err}"
|
|
406
407
|
|
|
407
408
|
if req["request_body"] && !req["request_body"].empty?
|
|
408
409
|
lines << "**Request Body:**"
|
|
@@ -76,15 +76,16 @@ module Profiler
|
|
|
76
76
|
if requests && !requests.empty?
|
|
77
77
|
lines << "## Request Details"
|
|
78
78
|
requests.each_with_index do |req, i|
|
|
79
|
-
slow_flag = req["duration"] >= threshold ? " [SLOW]" : ""
|
|
80
|
-
|
|
79
|
+
slow_flag = (req["duration"] || 0).to_f >= threshold ? " [SLOW]" : ""
|
|
80
|
+
status = req["status"].to_i
|
|
81
|
+
err_flag = status >= 400 || status == 0 ? " [ERROR]" : ""
|
|
81
82
|
lines << "\n### Request #{i + 1}#{slow_flag}#{err_flag}"
|
|
82
83
|
lines << "- **ID:** #{req['id']}" if req["id"]
|
|
83
84
|
lines << "- **Started at:** #{req['started_at']}" if req["started_at"]
|
|
84
85
|
lines << "- **Method:** #{req['method']}"
|
|
85
86
|
lines << "- **URL:** #{req['url']}"
|
|
86
|
-
lines << "- **Status:** #{
|
|
87
|
-
lines << "- **Duration:** #{req['duration'].round(2)} ms"
|
|
87
|
+
lines << "- **Status:** #{status == 0 ? 'connection error' : status}"
|
|
88
|
+
lines << "- **Duration:** #{(req['duration'] || 0).to_f.round(2)} ms"
|
|
88
89
|
lines << "- **Request Size:** #{req['request_size'].nil? ? 'unknown' : "#{'at least ' if req['request_size_is_minimum']}#{req['request_size']} bytes"}"
|
|
89
90
|
lines << "- **Response Size:** #{req['response_size']} bytes"
|
|
90
91
|
if req["request_body_not_captured"]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Profiler
|
|
4
|
+
module Middleware
|
|
5
|
+
# Validation of CORS configuration at boot time.
|
|
6
|
+
module CorsPolicy
|
|
7
|
+
module_function
|
|
8
|
+
|
|
9
|
+
# Logged once at boot when cors_allowed_origins contains "*", which is dangerous.
|
|
10
|
+
def warn_about_configuration(logger)
|
|
11
|
+
return unless Profiler.configuration.extension_cors_enabled
|
|
12
|
+
return unless Array(Profiler.configuration.cors_allowed_origins).include?("*")
|
|
13
|
+
|
|
14
|
+
Profiler.log_warn(
|
|
15
|
+
"CORS: '*' (wildcard origin) is set in cors_allowed_origins, which allows any website to access " \
|
|
16
|
+
"the profiler if a visitor browses the profiler. Set cors_allowed_origins to specific origins instead.",
|
|
17
|
+
logger: logger
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/profiler/peers.rb
CHANGED
|
@@ -56,6 +56,7 @@ module Profiler
|
|
|
56
56
|
def token_problem
|
|
57
57
|
token = Profiler.configuration.peer_token.to_s
|
|
58
58
|
return "No config.peer_token is configured" if token.strip.empty?
|
|
59
|
+
return "config.peer_token is surrounded by spaces or newlines, which breaks HTTP requests" if token != token.strip
|
|
59
60
|
return nil if token.strip.length >= MIN_TOKEN_LENGTH
|
|
60
61
|
|
|
61
62
|
"config.peer_token is shorter than #{MIN_TOKEN_LENGTH} characters, so it is ignored as if none were configured"
|
data/lib/profiler/railtie.rb
CHANGED
|
@@ -123,6 +123,13 @@ module Profiler
|
|
|
123
123
|
end
|
|
124
124
|
end
|
|
125
125
|
|
|
126
|
+
initializer "profiler.warn_cors_configuration", after: :load_config_initializers do
|
|
127
|
+
next unless Profiler.configuration.enabled
|
|
128
|
+
|
|
129
|
+
require_relative "middleware/cors_policy"
|
|
130
|
+
Profiler::Middleware::CorsPolicy.warn_about_configuration(Rails.logger)
|
|
131
|
+
end
|
|
132
|
+
|
|
126
133
|
initializer "profiler.start_cluster_client" do
|
|
127
134
|
# Check slave? inside on_load, the app's own initializers (config/initializers/profiler.rb)
|
|
128
135
|
# set master_url AFTER railtie initializers run, so the check must happen after_initialize.
|
data/lib/profiler/redaction.rb
CHANGED
|
@@ -5,6 +5,7 @@ require "set"
|
|
|
5
5
|
require "rack/utils"
|
|
6
6
|
require "active_support/parameter_filter"
|
|
7
7
|
require_relative "cluster/security"
|
|
8
|
+
require_relative "peers"
|
|
8
9
|
|
|
9
10
|
module Profiler
|
|
10
11
|
# The single filter applied to everything the profiler captures: request
|
|
@@ -289,13 +290,16 @@ module Profiler
|
|
|
289
290
|
|
|
290
291
|
private
|
|
291
292
|
|
|
292
|
-
# Only
|
|
293
|
-
#
|
|
294
|
-
#
|
|
293
|
+
# Only secrets the cluster or peers would use (long enough once stripped): a
|
|
294
|
+
# shorter one is ignored, and masking "true" or "/" everywhere would hide the
|
|
295
|
+
# very data profiled. Padded values are refused for requests but stay masked.
|
|
295
296
|
def credential_values
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
[
|
|
297
|
+
secret = Profiler.configuration.cluster_secret.to_s.strip
|
|
298
|
+
token = Profiler.configuration.peer_token.to_s.strip
|
|
299
|
+
credentials = []
|
|
300
|
+
credentials << secret if secret.length >= Cluster::Security::MIN_SECRET_LENGTH
|
|
301
|
+
credentials << token if token.length >= Peers::MIN_TOKEN_LENGTH
|
|
302
|
+
credentials
|
|
299
303
|
end
|
|
300
304
|
|
|
301
305
|
def hide_in(value, credentials)
|
|
@@ -86,7 +86,7 @@ namespace :profiler do
|
|
|
86
86
|
task mcp: :environment do
|
|
87
87
|
require_relative "../mcp/server"
|
|
88
88
|
|
|
89
|
-
transport = ENV["MCP_TRANSPORT"]&.to_sym ||
|
|
89
|
+
transport = ENV["MCP_TRANSPORT"]&.to_sym || :stdio
|
|
90
90
|
$stderr.puts "Starting Profiler MCP server (#{transport} transport)..."
|
|
91
91
|
|
|
92
92
|
server = Profiler::MCP::Server.new
|
data/lib/profiler/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.44.25
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sébastien Duplessy
|
|
@@ -240,6 +240,7 @@ files:
|
|
|
240
240
|
- lib/profiler/mcp/tools/set_env_var.rb
|
|
241
241
|
- lib/profiler/middleware/capturing_body.rb
|
|
242
242
|
- lib/profiler/middleware/cors_middleware.rb
|
|
243
|
+
- lib/profiler/middleware/cors_policy.rb
|
|
243
244
|
- lib/profiler/middleware/profiler_middleware.rb
|
|
244
245
|
- lib/profiler/middleware/streamed_profile.rb
|
|
245
246
|
- lib/profiler/middleware/toolbar_injector.rb
|