rails-profiler 0.44.16 → 0.44.17
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 +9 -0
- data/app/controllers/profiler/api/env_vars_controller.rb +15 -0
- data/lib/profiler/configuration.rb +52 -0
- data/lib/profiler/env_override_store.rb +19 -2
- 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: 35e6f32ca6ce4fe99441b079cd304f93539eacb3dffa267af96ce6945d14911b
|
|
4
|
+
data.tar.gz: '014679015c78eb282be8f5ee19cb6a97be988f182ae91e1e7e33ddade5db3bd5'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e66c36f8ac5120128e2f1ac069fa770ba141ab707f63f072fac704258333be9175065ad3fcac9940ef2fdbd3a0c22dc50eb452fa7b06bd17df4985492545d66d
|
|
7
|
+
data.tar.gz: 8637901e09759b2532300b92bbf9de2f0d4cd4ddf4aba1669cdc25b0ebc2ef2ca5045b0f91538e429d18d75f25301ebcb51f34f3e35b6acd31cd8db36a10b10c
|
data/CHANGELOG.md
CHANGED
|
@@ -19,6 +19,15 @@ every commit of every tag interval is accounted for one way or the other.
|
|
|
19
19
|
|
|
20
20
|
## [Unreleased]
|
|
21
21
|
|
|
22
|
+
## [0.44.17] - 2026-10-25
|
|
23
|
+
|
|
24
|
+
<!-- stamped -->
|
|
25
|
+
|
|
26
|
+
### Security
|
|
27
|
+
|
|
28
|
+
- **EnvOverrides:** the profiler now refuses to restore environment variables blocked by `EnvKeyPolicy` when a reset is requested, closing a bypass where protected keys (DATABASE_URL, RUBYOPT, etc.) could be restored from persisted overrides.
|
|
29
|
+
- **Authorization:** the profiler now validates the Host header against local names, `config.hosts` and `config.mcp_allowed_hosts` in all authorization modes, including `:allow_authorized`, preventing DNS rebinding attacks when using custom authorization blocks.
|
|
30
|
+
|
|
22
31
|
## [0.44.16] - 2026-10-23
|
|
23
32
|
|
|
24
33
|
<!-- stamped -->
|
|
@@ -70,7 +70,22 @@ module Profiler
|
|
|
70
70
|
return
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
+
# EnvOverrideStore#reset already drops a blocked key from the overrides file instead of
|
|
74
|
+
# restoring it (see EnvKeyPolicy), so this removes a stale entry left by an older version
|
|
75
|
+
# the same way reset_all and the MCP reset_env_var tool do, rather than leaving it stuck
|
|
76
|
+
# until a full reset_all. An invalid or reserved name is a different, pre-existing case
|
|
77
|
+
# (cleaning up garbage left in the file): it is removed the same way, without an error.
|
|
73
78
|
Profiler.env_override_store.reset(key)
|
|
79
|
+
|
|
80
|
+
# code_loading? also answers true for an invalid name (by design, for the test runner):
|
|
81
|
+
# excluded here, since an invalid name is cleaned up without an error, not "protected".
|
|
82
|
+
if Profiler::EnvKeyPolicy.valid_name?(key) &&
|
|
83
|
+
(Profiler::EnvKeyPolicy.protected?(key) || Profiler::EnvKeyPolicy.code_loading?(key))
|
|
84
|
+
render json: { error: "#{key} is protected; it was removed from the overrides but not restored" },
|
|
85
|
+
status: :unprocessable_entity
|
|
86
|
+
return
|
|
87
|
+
end
|
|
88
|
+
|
|
74
89
|
render json: { key: key, value: redacted_value(key), reset: true }
|
|
75
90
|
end
|
|
76
91
|
|
|
@@ -403,6 +403,17 @@ module Profiler
|
|
|
403
403
|
LocalRequest.warn_once(reason)
|
|
404
404
|
false
|
|
405
405
|
when :allow_authorized
|
|
406
|
+
# DNS rebinding protection: validate the Host header even when using a custom
|
|
407
|
+
# authorization block. The block may rely on REMOTE_ADDR (e.g., docker.include?(REMOTE_ADDR)),
|
|
408
|
+
# which is not enough: an attacker can reach an allowed address with a Host header under
|
|
409
|
+
# their control, bypassing the block's intent. A deployment that is reached under a
|
|
410
|
+
# non-loopback name (a reverse proxy, a Docker network alias) must list it in config.hosts
|
|
411
|
+
# or config.mcp_allowed_hosts, same as the MCP HTTP transport already requires.
|
|
412
|
+
if (denial = authorized_host_denial_reason(request))
|
|
413
|
+
warn_once_authorized_host(denial)
|
|
414
|
+
return false
|
|
415
|
+
end
|
|
416
|
+
|
|
406
417
|
run_authorize_block(request)
|
|
407
418
|
else
|
|
408
419
|
false
|
|
@@ -500,6 +511,47 @@ module Profiler
|
|
|
500
511
|
"host name (#{e.message})"
|
|
501
512
|
end
|
|
502
513
|
|
|
514
|
+
# The DNS rebinding check for :allow_authorized: nil when the Host and X-Forwarded-Host
|
|
515
|
+
# headers are allowed, otherwise a sentence naming the cause. A host is allowed when it is
|
|
516
|
+
# local, listed in config.hosts, or listed in config.mcp_allowed_hosts: the same rule the MCP
|
|
517
|
+
# HTTP transport already applies (Profiler::MCP::HttpGuard.allowed_host?), so a deployment
|
|
518
|
+
# that already lists its host for MCP does not have to list it twice.
|
|
519
|
+
def authorized_host_denial_reason(request)
|
|
520
|
+
require_relative "mcp/http_guard"
|
|
521
|
+
|
|
522
|
+
# An empty Host header, like a missing one, does not come from a browser (HTTP/1.1
|
|
523
|
+
# requires it): HttpGuard.allowed_host? only treats nil that way, so blank is checked here.
|
|
524
|
+
raw_host = request.get_header("HTTP_HOST").to_s
|
|
525
|
+
unless raw_host.empty? || MCP::HttpGuard.allowed_host?(raw_host, self)
|
|
526
|
+
return "the Host header #{raw_host.inspect} is not allowed: list it in config.hosts or " \
|
|
527
|
+
"config.mcp_allowed_hosts"
|
|
528
|
+
end
|
|
529
|
+
|
|
530
|
+
forwarded_hosts = request.get_header("HTTP_X_FORWARDED_HOST").to_s.split(",")
|
|
531
|
+
remote = forwarded_hosts.find { |h| !MCP::HttpGuard.allowed_host?(h, self) }
|
|
532
|
+
return "the X-Forwarded-Host header #{remote.inspect} is not allowed: list it in config.hosts or " \
|
|
533
|
+
"config.mcp_allowed_hosts" if remote
|
|
534
|
+
|
|
535
|
+
nil
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
# Logged once per process, like LocalRequest.warn_once for :allow_local: an operator seeing
|
|
539
|
+
# the profiler go dark under :allow_authorized needs to know the Host check is the cause, not
|
|
540
|
+
# a silently rejecting authorize_with block.
|
|
541
|
+
def warn_once_authorized_host(reason)
|
|
542
|
+
@warn_authorized_host_mutex ||= Mutex.new
|
|
543
|
+
@warn_authorized_host_mutex.synchronize do
|
|
544
|
+
return if @warned_authorized_host
|
|
545
|
+
|
|
546
|
+
@warned_authorized_host = true
|
|
547
|
+
end
|
|
548
|
+
|
|
549
|
+
Profiler.log_warn(
|
|
550
|
+
"Request refused by authorization_mode :allow_authorized before the authorize_with " \
|
|
551
|
+
"block ran: #{reason}. This message is logged once per process."
|
|
552
|
+
)
|
|
553
|
+
end
|
|
554
|
+
|
|
503
555
|
# An exception in the application's own authorization code is a denial, never an error
|
|
504
556
|
# for the request: it would otherwise break every request. The detail stays in the log.
|
|
505
557
|
def run_authorize_block(request)
|
|
@@ -81,8 +81,13 @@ module Profiler
|
|
|
81
81
|
surfacing("reset #{key}") do
|
|
82
82
|
update_overrides do |overrides|
|
|
83
83
|
entry = overrides[key]
|
|
84
|
-
# Keep a RESTORE entry so Sidekiq workers pick it up on next job
|
|
85
|
-
|
|
84
|
+
# Keep a RESTORE entry so Sidekiq workers pick it up on next job, but remove the key
|
|
85
|
+
# entirely if it is blocked by EnvKeyPolicy: refusing to restore protected keys
|
|
86
|
+
# applies even when reading from persisted overrides.
|
|
87
|
+
if entry
|
|
88
|
+
overrides[key] = EnvKeyPolicy.allowed?(key) ? restore_entry(entry["original"]) : nil
|
|
89
|
+
overrides.delete(key) if overrides[key].nil?
|
|
90
|
+
end
|
|
86
91
|
end
|
|
87
92
|
end
|
|
88
93
|
|
|
@@ -98,6 +103,14 @@ module Profiler
|
|
|
98
103
|
# Already reset: its reset_at stays, so that it still expires.
|
|
99
104
|
next if restore_entry?(entry)
|
|
100
105
|
|
|
106
|
+
# Remove keys blocked by EnvKeyPolicy entirely instead of leaving a RESTORE sentinel,
|
|
107
|
+
# preventing persisted overrides from restoring protected variables.
|
|
108
|
+
unless EnvKeyPolicy.allowed?(key)
|
|
109
|
+
originals[key] = nil
|
|
110
|
+
overrides.delete(key)
|
|
111
|
+
next
|
|
112
|
+
end
|
|
113
|
+
|
|
101
114
|
originals[key] = entry.is_a?(Hash) ? entry["original"] : nil
|
|
102
115
|
# Leave a RESTORE sentinel for Sidekiq workers to pick up
|
|
103
116
|
overrides[key] = restore_entry(originals[key])
|
|
@@ -289,6 +302,10 @@ module Profiler
|
|
|
289
302
|
# entry is reset in the file, and there is nothing to put back here.
|
|
290
303
|
return false unless EnvKeyPolicy.valid_name?(key)
|
|
291
304
|
return false if EnvKeyPolicy.value_rejection(key, original)
|
|
305
|
+
# Do not restore environment variables blocked by EnvKeyPolicy: refusal to restore a
|
|
306
|
+
# protected key (DATABASE_URL, RUBYOPT, etc.) applies even when reloading persisted
|
|
307
|
+
# overrides from file, preventing bypasses through legacy override files.
|
|
308
|
+
return false unless EnvKeyPolicy.allowed?(key)
|
|
292
309
|
|
|
293
310
|
original.nil? ? ENV.delete(key) : ENV[key] = original
|
|
294
311
|
true
|
data/lib/profiler/version.rb
CHANGED