featureflip 2.14.0 → 2.15.0
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/lib/featureflip/redacting_logger.rb +121 -0
- data/lib/featureflip/shared_core.rb +25 -7
- data/lib/featureflip/version.rb +1 -1
- data/lib/featureflip.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 15b0723d1722a5537c1d86f006e1b31f44041a3375821037bd120f0638cf4ea8
|
|
4
|
+
data.tar.gz: 2ee4100d6030d53db2d8ed3d6b281d2d365fe0ffbcb927ed2754236c404cc20f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 29e129490227e460f958a12f5912127df85617cffa97365f909a83d7b638cae0c379cbf47bdcb32242b0671f0ccf934adceb4c4b3757eeabe928a14186131718
|
|
7
|
+
data.tar.gz: 906d860e2606afb9db5a5d83d7ad561fbf97b7d97899215f9f7504e14b0e990f749846246d3041bf22422e48c488c7c996a5f16111a9daeb84888fc219bd1f19
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
module Featureflip
|
|
2
|
+
# Strips the SDK key out of anything the SDK logs (#5167).
|
|
3
|
+
#
|
|
4
|
+
# Failure paths report the underlying exception verbatim, so a config-load failure is
|
|
5
|
+
# never silent. That exception can come from a transport the SDK does not control, and
|
|
6
|
+
# the SDK sets the key as the Authorization header on every request: a client that
|
|
7
|
+
# quotes request headers in its message would hand the credential to whatever the host
|
|
8
|
+
# logs to (#5152 was the same leak from a call site).
|
|
9
|
+
#
|
|
10
|
+
# Applied once, as a decorator around the resolved logger when a core is built, so it
|
|
11
|
+
# covers every call site that exists today and any added later, and the default
|
|
12
|
+
# logger too -- stdout is no safer a place for a credential than an aggregator.
|
|
13
|
+
#
|
|
14
|
+
# @api private
|
|
15
|
+
class RedactingLogger
|
|
16
|
+
REPLACEMENT = "[redacted]".freeze
|
|
17
|
+
|
|
18
|
+
# Below this the value is not treated as a credential. A real key is always 54
|
|
19
|
+
# characters; redacting a short one corrupts every line it appears inside (with the
|
|
20
|
+
# key "k", "skipped" becomes "s[redacted]ipped"). A string too short to be a
|
|
21
|
+
# Featureflip key cannot authenticate, so there is nothing to protect.
|
|
22
|
+
MIN_REDACTABLE_LENGTH = 20
|
|
23
|
+
|
|
24
|
+
# Independent of any logger, so the exceptions the SDK raises can be scrubbed even
|
|
25
|
+
# when the host configured no logger.
|
|
26
|
+
def self.redact(text, secret)
|
|
27
|
+
secret = secret.to_s
|
|
28
|
+
return text unless text.is_a?(String) && secret.length >= MIN_REDACTABLE_LENGTH
|
|
29
|
+
|
|
30
|
+
text.gsub(secret, REPLACEMENT)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.wrap(logger, secret)
|
|
34
|
+
return logger if logger.nil? || logger.is_a?(RedactingLogger)
|
|
35
|
+
|
|
36
|
+
new(logger, secret)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def initialize(inner, secret)
|
|
40
|
+
@inner = inner
|
|
41
|
+
@secret = secret.to_s
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
%i[debug info warn error fatal unknown].each do |name|
|
|
45
|
+
define_method(name) do |message = nil, &block|
|
|
46
|
+
if block
|
|
47
|
+
@inner.public_send(name, redact_object(message)) { redact_object(block.call) }
|
|
48
|
+
else
|
|
49
|
+
@inner.public_send(name, redact_object(message))
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def add(severity, message = nil, progname = nil, &block)
|
|
55
|
+
if block
|
|
56
|
+
@inner.add(severity, redact_object(message), redact_object(progname)) { redact_object(block.call) }
|
|
57
|
+
else
|
|
58
|
+
@inner.add(severity, redact_object(message), redact_object(progname))
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
alias_method :log, :add
|
|
62
|
+
|
|
63
|
+
def <<(message)
|
|
64
|
+
@inner << redact_object(message)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def progname
|
|
68
|
+
redact_object(@inner.progname)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def method_missing(name, *args, **kwargs, &block)
|
|
72
|
+
return super unless @inner.respond_to?(name)
|
|
73
|
+
|
|
74
|
+
@inner.public_send(name, *args, **kwargs, &block)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def respond_to_missing?(name, include_private = false)
|
|
78
|
+
@inner.respond_to?(name) || super
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def redact(text)
|
|
82
|
+
self.class.redact(text, @secret)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
private
|
|
86
|
+
|
|
87
|
+
def redactable?
|
|
88
|
+
@secret.length >= MIN_REDACTABLE_LENGTH
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def redact_object(object)
|
|
92
|
+
return object unless redactable?
|
|
93
|
+
|
|
94
|
+
case object
|
|
95
|
+
when String then redact(object)
|
|
96
|
+
when Exception then redact_exception(object)
|
|
97
|
+
when nil, Symbol, Numeric, true, false then object
|
|
98
|
+
else
|
|
99
|
+
# The logger would render this with #inspect; only touch it when the key is in it.
|
|
100
|
+
# Skipped entirely when the logger would discard the line anyway.
|
|
101
|
+
return object unless @inner.respond_to?(:level) && @inner.level.to_i <= Logger::FATAL
|
|
102
|
+
|
|
103
|
+
text = object.inspect
|
|
104
|
+
text.include?(@secret) ? redact(text) : object
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Logger's formatter prints "message (Class)" plus the backtrace. A clean exception
|
|
109
|
+
# is passed through as the original object (structured consumers keep it); a dirty
|
|
110
|
+
# one is rendered from the redacted message so the sink never sees the original.
|
|
111
|
+
def redact_exception(error)
|
|
112
|
+
message = error.message.to_s
|
|
113
|
+
backtrace = Array(error.backtrace)
|
|
114
|
+
return error unless message.include?(@secret) || backtrace.any? { |l| l.include?(@secret) }
|
|
115
|
+
|
|
116
|
+
lines = ["#{redact(message)} (#{error.class})"]
|
|
117
|
+
lines.concat(backtrace.map { |l| redact(l) })
|
|
118
|
+
lines.join("\n")
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -40,12 +40,12 @@ module Featureflip
|
|
|
40
40
|
if existing
|
|
41
41
|
if existing._acquire
|
|
42
42
|
unless _configs_equal(existing._config, config)
|
|
43
|
-
config.logger&.warn(
|
|
43
|
+
RedactingLogger.wrap(config.logger, sdk_key)&.warn(
|
|
44
44
|
"Featureflip: Client.get called with different config for same SDK key. " \
|
|
45
45
|
"Using existing configuration. Close all handles first to apply new config."
|
|
46
46
|
)
|
|
47
47
|
end
|
|
48
|
-
_warn_snapshot_options_ignored(existing._config, config)
|
|
48
|
+
_warn_snapshot_options_ignored(existing._config, config, sdk_key)
|
|
49
49
|
return existing
|
|
50
50
|
else
|
|
51
51
|
# Stale entry — remove and replace
|
|
@@ -63,13 +63,13 @@ module Featureflip
|
|
|
63
63
|
# passes a different store instance, or an explicit different max age, is told so.
|
|
64
64
|
# An omitted store or max age is not a request, so a wrapper that does not forward
|
|
65
65
|
# them never triggers the warning.
|
|
66
|
-
def self._warn_snapshot_options_ignored(existing, requested)
|
|
66
|
+
def self._warn_snapshot_options_ignored(existing, requested, sdk_key)
|
|
67
67
|
store_differs = !requested.snapshot_store.nil? && !requested.snapshot_store.equal?(existing.snapshot_store)
|
|
68
68
|
age_differs = requested.max_snapshot_age_explicit? &&
|
|
69
69
|
requested.max_snapshot_age_seconds != existing.max_snapshot_age_seconds
|
|
70
70
|
return unless store_differs || age_differs
|
|
71
71
|
|
|
72
|
-
requested.logger&.warn(
|
|
72
|
+
RedactingLogger.wrap(requested.logger, sdk_key)&.warn(
|
|
73
73
|
"Featureflip: snapshot_store/max_snapshot_age_seconds option ignored because a client " \
|
|
74
74
|
"for this SDK key already exists. Close all handles first to apply it."
|
|
75
75
|
)
|
|
@@ -103,7 +103,11 @@ module Featureflip
|
|
|
103
103
|
|
|
104
104
|
def initialize(sdk_key:, config:, clock: SYSTEM_CLOCK)
|
|
105
105
|
@sdk_key = sdk_key
|
|
106
|
-
@config
|
|
106
|
+
# Every log line the SDK writes goes through @config.logger, so wrapping it here,
|
|
107
|
+
# once, keeps the key out of all of them (#5167). A copy: the caller's Config (and
|
|
108
|
+
# its logger) stay untouched.
|
|
109
|
+
@config = config.dup
|
|
110
|
+
@config.logger = RedactingLogger.wrap(config.logger, sdk_key)
|
|
107
111
|
@clock = clock
|
|
108
112
|
init_snapshot_state
|
|
109
113
|
# Snapshot the (already-filtered) inspector list at construction: config is
|
|
@@ -379,6 +383,20 @@ module Featureflip
|
|
|
379
383
|
@config.logger&.info("Featureflip: core shut down")
|
|
380
384
|
end
|
|
381
385
|
|
|
386
|
+
def redact(text)
|
|
387
|
+
RedactingLogger.redact(text, @sdk_key)
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
# The caller sees the failure's class, message and backtrace with the key scrubbed.
|
|
391
|
+
# The original exception is not chained: its message may quote the Authorization
|
|
392
|
+
# header, and an explicit cause: stops Ruby attaching it as #cause implicitly.
|
|
393
|
+
def raise_sanitized_init_error(error)
|
|
394
|
+
sanitized = RuntimeError.new("#{error.class}: #{redact(error.message.to_s)}")
|
|
395
|
+
sanitized.set_backtrace(error.backtrace&.map { |l| redact(l) })
|
|
396
|
+
raise InitializationError.new("Failed to initialize: #{redact(error.message.to_s)} (#{error.class})"),
|
|
397
|
+
cause: sanitized
|
|
398
|
+
end
|
|
399
|
+
|
|
382
400
|
def bootstrap!
|
|
383
401
|
@http_client = Http::Client.new(@sdk_key, @config)
|
|
384
402
|
fetch_initial_flags
|
|
@@ -405,7 +423,7 @@ module Featureflip
|
|
|
405
423
|
rescue InitializationError
|
|
406
424
|
raise
|
|
407
425
|
rescue StandardError => e
|
|
408
|
-
|
|
426
|
+
raise_sanitized_init_error(e) if @config.snapshot_store.nil?
|
|
409
427
|
|
|
410
428
|
fall_back_to_snapshot(e, timed_out: false)
|
|
411
429
|
end
|
|
@@ -421,7 +439,7 @@ module Featureflip
|
|
|
421
439
|
return "timed out after #{@config.init_timeout}s" if timed_out
|
|
422
440
|
return "HTTP #{error.status}" if error.respond_to?(:status) && error.status.is_a?(Integer)
|
|
423
441
|
|
|
424
|
-
message = error.message.to_s
|
|
442
|
+
message = redact(error.message.to_s)
|
|
425
443
|
message.empty? ? error.class.name : message
|
|
426
444
|
end
|
|
427
445
|
|
data/lib/featureflip/version.rb
CHANGED
data/lib/featureflip.rb
CHANGED
|
@@ -2,6 +2,7 @@ require_relative "featureflip/version"
|
|
|
2
2
|
require_relative "featureflip/errors"
|
|
3
3
|
require_relative "featureflip/config"
|
|
4
4
|
require_relative "featureflip/sdk_identity"
|
|
5
|
+
require_relative "featureflip/redacting_logger"
|
|
5
6
|
require_relative "featureflip/models/flag"
|
|
6
7
|
require_relative "featureflip/models/segment"
|
|
7
8
|
require_relative "featureflip/models/evaluation_detail"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: featureflip
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.15.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Featureflip
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: logger
|
|
@@ -91,6 +91,7 @@ files:
|
|
|
91
91
|
- lib/featureflip/models/evaluation_event.rb
|
|
92
92
|
- lib/featureflip/models/flag.rb
|
|
93
93
|
- lib/featureflip/models/segment.rb
|
|
94
|
+
- lib/featureflip/redacting_logger.rb
|
|
94
95
|
- lib/featureflip/sdk_identity.rb
|
|
95
96
|
- lib/featureflip/shared_core.rb
|
|
96
97
|
- lib/featureflip/snapshot.rb
|