otto 2.8.0 → 2.8.1

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.
@@ -24,6 +24,10 @@ class Otto
24
24
  # config = Otto::Privacy::Config.new
25
25
  # config.octet_precision = 2 # Mask 2 octets instead of 1
26
26
  #
27
+ # rubocop:disable Metrics/ClassLength -- three parallel database
28
+ # configurations (geo, ASN, anonymizer) live here by design: each is a
29
+ # thin, symmetric writer/reader/loader trio, and splitting them into
30
+ # modules would hide the symmetry that makes them reviewable.
27
31
  class Config
28
32
  include Otto::Core::Freezable
29
33
 
@@ -49,8 +53,10 @@ class Otto
49
53
  audit: { disabled: true }.freeze,
50
54
  }.freeze
51
55
 
52
- attr_accessor :octet_precision, :hash_rotation_period, :geo_enabled, :mask_private_ips
53
- attr_reader :disabled, :correlation_secret, :geo_header, :geo_db_path
56
+ attr_accessor :octet_precision, :hash_rotation_period, :geo_enabled, :mask_private_ips,
57
+ :asn_enabled, :anonymizer_enabled
58
+ attr_reader :disabled, :correlation_secret, :geo_header, :geo_db_path,
59
+ :asn_db_path, :anonymizer_db_path
54
60
 
55
61
  # Class-level rotation key storage (mutable, not frozen with instances)
56
62
  # This is stored at the class level so it persists across frozen config instances
@@ -82,6 +88,23 @@ class Otto
82
88
  # @option options [#get] :geo_db_reader Bring-your-own MMDB reader (any object responding
83
89
  # to #get, e.g. a MaxMind::DB or a compatible reader). Overrides :geo_db_path when set,
84
90
  # so the reader choice stays independent of Otto. Default nil.
91
+ # @option options [Boolean] :asn_enabled Enable ASN resolution (default: FALSE — unlike
92
+ # :geo_enabled, this signal is opt-in, so a deployment that never asks for it pays
93
+ # nothing and no database is opened)
94
+ # @option options [String] :asn_db_path Filesystem path to a MaxMind-format (.mmdb) ASN
95
+ # database (looked up on the already MASKED IP, like the geo database). Requires the
96
+ # 'maxmind-db' gem. A bad/unreadable path raises at boot, not per-request. Default nil.
97
+ # @option options [#get] :asn_db_reader Bring-your-own MMDB reader for ASN lookups (any
98
+ # object responding to #get). Overrides :asn_db_path when set. Default nil.
99
+ # @option options [Boolean] :anonymizer_enabled Enable anonymizer (Tor/VPN/proxy/hosting)
100
+ # classification (default: FALSE — opt-in, same as :asn_enabled)
101
+ # @option options [String] :anonymizer_db_path Filesystem path to a MaxMind-format (.mmdb)
102
+ # anonymous-IP database. Looked up on the UNMASKED IP — anonymizer data lists individual
103
+ # egress nodes at /32, so a masked lookup would answer for the node's neighbours; only
104
+ # the resulting label leaves the resolver. Requires the 'maxmind-db' gem. A bad path
105
+ # raises at boot. Default nil.
106
+ # @option options [#get] :anonymizer_db_reader Bring-your-own MMDB reader for anonymizer
107
+ # lookups (any object responding to #get). Overrides :anonymizer_db_path. Default nil.
85
108
  # @option options [Boolean] :disabled Disable privacy entirely (default: false)
86
109
  # @option options [Boolean] :mask_private_ips Mask private/localhost IPs (default: false)
87
110
  # @option options [String] :correlation_secret A secret string that turns
@@ -119,8 +142,24 @@ class Otto
119
142
  @geo_db_override = nil # reader injected via geo_db_reader= (wins over path)
120
143
  self.geo_header = options[:geo_header] # canonicalized to an HTTP_* env key (or nil)
121
144
  self.geo_db_reader = options[:geo_db_reader] if options.key?(:geo_db_reader)
122
- @geo_db_path = normalize_geo_db_path(options[:geo_db_path])
145
+ @geo_db_path = normalize_db_path(options[:geo_db_path])
123
146
  load_geo_database! # build/attach the reader now so a bad path fails at boot
147
+
148
+ # ASN enrichment (opt-in, boot-time only). Same two-ivar shape as geo.
149
+ @asn_enabled = options.fetch(:asn_enabled, false)
150
+ @asn_db_reader = nil
151
+ @asn_db_override = nil
152
+ self.asn_db_reader = options[:asn_db_reader] if options.key?(:asn_db_reader)
153
+ @asn_db_path = normalize_db_path(options[:asn_db_path])
154
+ load_asn_database!
155
+
156
+ # Anonymizer classification (opt-in, boot-time only).
157
+ @anonymizer_enabled = options.fetch(:anonymizer_enabled, false)
158
+ @anonymizer_db_reader = nil
159
+ @anonymizer_db_override = nil
160
+ self.anonymizer_db_reader = options[:anonymizer_db_reader] if options.key?(:anonymizer_db_reader)
161
+ @anonymizer_db_path = normalize_db_path(options[:anonymizer_db_path])
162
+ load_anonymizer_database!
124
163
  end
125
164
 
126
165
  # Set the stable correlation secret, validating its type up front.
@@ -163,7 +202,42 @@ class Otto
163
202
  #
164
203
  # @param value [String, nil] filesystem path to a .mmdb file, or nil
165
204
  def geo_db_path=(value)
166
- @geo_db_path = normalize_geo_db_path(value)
205
+ @geo_db_path = normalize_db_path(value)
206
+ end
207
+
208
+ # Path to a MaxMind-format ASN database. See {#geo_db_path=}; the same
209
+ # boot-time contract applies — call {#load_asn_database!} to attach it.
210
+ #
211
+ # @param value [String, nil] filesystem path to a .mmdb file, or nil
212
+ def asn_db_path=(value)
213
+ @asn_db_path = normalize_db_path(value)
214
+ end
215
+
216
+ # Path to a MaxMind-format anonymous-IP database. See {#geo_db_path=};
217
+ # call {#load_anonymizer_database!} to attach it.
218
+ #
219
+ # @param value [String, nil] filesystem path to a .mmdb file, or nil
220
+ def anonymizer_db_path=(value)
221
+ @anonymizer_db_path = normalize_db_path(value)
222
+ end
223
+
224
+ # Replace one enrichment database path only after its new reader has
225
+ # opened successfully. Used by the boot-time configuration path; direct
226
+ # callers should normally use Otto#configure_ip_privacy.
227
+ #
228
+ # @param prefix [:asn, :anonymizer] database source to replace
229
+ # @param value [String, nil] new database path
230
+ # @return [void]
231
+ # @raise [ArgumentError] if an enabled signal's path cannot be opened
232
+ # @api private
233
+ def replace_enrichment_database_path!(prefix, value)
234
+ path = normalize_db_path(value)
235
+ enabled = instance_variable_get(:"@#{prefix}_enabled")
236
+ reader = path && enabled ? build_maxmind_reader(path, option_name: "#{prefix}_db_path") : nil
237
+
238
+ instance_variable_set(:"@#{prefix}_db_path", path)
239
+ instance_variable_set(:"@#{prefix}_db_override", nil)
240
+ instance_variable_set(:"@#{prefix}_db_reader", reader)
167
241
  end
168
242
 
169
243
  # Inject a ready-made MMDB reader (any object responding to #get).
@@ -202,6 +276,45 @@ class Otto
202
276
  @geo_enabled ? @geo_db_reader : nil
203
277
  end
204
278
 
279
+ # Inject a ready-made MMDB reader for ASN lookups. See {#geo_db_reader=}.
280
+ #
281
+ # @param reader [#get, nil] MMDB-compatible reader, or nil to clear
282
+ # @raise [ArgumentError] if reader does not respond to :get
283
+ def asn_db_reader=(reader)
284
+ unless reader.nil? || reader.respond_to?(:get)
285
+ raise ArgumentError, "asn_db_reader must respond to :get, got: #{reader.class}"
286
+ end
287
+
288
+ @asn_db_override = reader
289
+ end
290
+
291
+ # The effective ASN reader, or nil when ASN resolution is off.
292
+ #
293
+ # @return [#get, nil]
294
+ def asn_db_reader
295
+ @asn_enabled ? @asn_db_reader : nil
296
+ end
297
+
298
+ # Inject a ready-made MMDB reader for anonymizer lookups.
299
+ # See {#geo_db_reader=}.
300
+ #
301
+ # @param reader [#get, nil] MMDB-compatible reader, or nil to clear
302
+ # @raise [ArgumentError] if reader does not respond to :get
303
+ def anonymizer_db_reader=(reader)
304
+ unless reader.nil? || reader.respond_to?(:get)
305
+ raise ArgumentError, "anonymizer_db_reader must respond to :get, got: #{reader.class}"
306
+ end
307
+
308
+ @anonymizer_db_override = reader
309
+ end
310
+
311
+ # The effective anonymizer reader, or nil when classification is off.
312
+ #
313
+ # @return [#get, nil]
314
+ def anonymizer_db_reader
315
+ @anonymizer_enabled ? @anonymizer_db_reader : nil
316
+ end
317
+
205
318
  # Build/attach the geo database reader for the current configuration.
206
319
  #
207
320
  # Boot-time only. Resolves the effective reader (injected override wins
@@ -224,6 +337,39 @@ class Otto
224
337
  end
225
338
  end
226
339
 
340
+ # Build/attach the ASN database reader. See {#load_geo_database!} — same
341
+ # boot-time contract, same override-wins-over-path resolution.
342
+ #
343
+ # @return [void]
344
+ # @raise [ArgumentError] if the path is unreadable or maxmind-db is absent
345
+ def load_asn_database!
346
+ @asn_db_reader = nil
347
+ return unless @asn_enabled
348
+
349
+ @asn_db_reader =
350
+ if @asn_db_override
351
+ @asn_db_override
352
+ elsif @asn_db_path
353
+ build_maxmind_reader(@asn_db_path, option_name: 'asn_db_path')
354
+ end
355
+ end
356
+
357
+ # Build/attach the anonymizer database reader. See {#load_geo_database!}.
358
+ #
359
+ # @return [void]
360
+ # @raise [ArgumentError] if the path is unreadable or maxmind-db is absent
361
+ def load_anonymizer_database!
362
+ @anonymizer_db_reader = nil
363
+ return unless @anonymizer_enabled
364
+
365
+ @anonymizer_db_reader =
366
+ if @anonymizer_db_override
367
+ @anonymizer_db_override
368
+ elsif @anonymizer_db_path
369
+ build_maxmind_reader(@anonymizer_db_path, option_name: 'anonymizer_db_path')
370
+ end
371
+ end
372
+
227
373
  # Look up the preset hash for a named profile, failing fast on typos.
228
374
  #
229
375
  # @param profile [Symbol, String] one of the {PROFILES} keys
@@ -368,11 +514,12 @@ class Otto
368
514
 
369
515
  private
370
516
 
371
- # Normalize a geo_db_path option to a non-empty String or nil.
517
+ # Normalize a database-path option to a non-empty String or nil. Shared by
518
+ # the geo, ASN and anonymizer paths — the rule is identical for all three.
372
519
  #
373
520
  # @param value [String, nil] raw path option
374
521
  # @return [String, nil]
375
- def normalize_geo_db_path(value)
522
+ def normalize_db_path(value)
376
523
  return nil if value.nil?
377
524
 
378
525
  path = value.to_s.strip
@@ -390,22 +537,22 @@ class Otto
390
537
  # @param path [String] filesystem path to a .mmdb file
391
538
  # @return [MaxMind::DB] in-memory reader
392
539
  # @raise [ArgumentError] if the path is unreadable or the gem is missing
393
- def build_maxmind_reader(path)
394
- raise ArgumentError, "geo_db_path is not readable: #{path.inspect}" unless File.readable?(path)
540
+ def build_maxmind_reader(path, option_name: 'geo_db_path')
541
+ raise ArgumentError, "#{option_name} is not readable: #{path.inspect}" unless File.readable?(path)
395
542
 
396
543
  begin
397
544
  require 'maxmind/db'
398
545
  rescue LoadError
399
546
  raise ArgumentError,
400
- "geo_db_path is set (#{path.inspect}) but the 'maxmind-db' gem is not available. " \
547
+ "#{option_name} is set (#{path.inspect}) but the 'maxmind-db' gem is not available. " \
401
548
  "Add `gem 'maxmind-db'` to your Gemfile, or inject your own reader via " \
402
- 'configure_ip_privacy(geo_db_reader: ...).'
549
+ "configure_ip_privacy(#{option_name.sub('_path', '_reader')}: ...)."
403
550
  end
404
551
 
405
552
  begin
406
553
  MaxMind::DB.new(path, mode: MaxMind::DB::MODE_MEMORY)
407
554
  rescue StandardError => e
408
- raise ArgumentError, "Failed to open geo_db_path #{path.inspect}: #{e.class}: #{e.message}"
555
+ raise ArgumentError, "Failed to open #{option_name} #{path.inspect}: #{e.class}: #{e.message}"
409
556
  end
410
557
  end
411
558
 
@@ -475,5 +622,6 @@ class Otto
475
622
  key
476
623
  end
477
624
  end
625
+ # rubocop:enable Metrics/ClassLength
478
626
  end
479
627
  end
@@ -102,7 +102,9 @@ class Otto
102
102
  # them into a hash would only obscure the supported settings.
103
103
  def configure_ip_privacy(octet_precision: nil, hash_rotation: nil, geo: nil, redis: nil,
104
104
  correlation_secret: nil, geo_header: nil, geo_db_path: nil,
105
- geo_db_reader: nil, profile: nil)
105
+ geo_db_reader: nil, profile: nil, asn: nil, asn_db_path: nil,
106
+ asn_db_reader: nil, anonymizer: nil, anonymizer_db_path: nil,
107
+ anonymizer_db_reader: nil)
106
108
  # rubocop:enable Metrics/ParameterLists
107
109
  ensure_not_frozen!
108
110
  config = @security_config.ip_privacy_config
@@ -130,6 +132,8 @@ class Otto
130
132
 
131
133
  apply_geo_config(config, geo: geo, geo_header: geo_header,
132
134
  geo_db_path: geo_db_path, geo_db_reader: geo_db_reader)
135
+ apply_enrichment_signal(config, :asn, asn, asn_db_path, asn_db_reader)
136
+ apply_enrichment_signal(config, :anonymizer, anonymizer, anonymizer_db_path, anonymizer_db_reader)
133
137
  end
134
138
 
135
139
  private
@@ -184,6 +188,54 @@ class Otto
184
188
 
185
189
  config.load_geo_database! if geo_touched
186
190
  end
191
+
192
+ # Apply one opt-in enrichment signal (ASN or anonymizer classification).
193
+ #
194
+ # Same contract as {#apply_geo_config}: nil means "leave unchanged", a
195
+ # reader supplied in this call wins over a path, and a path supplied on
196
+ # its own clears any prior injected reader so it actually takes effect.
197
+ # Any touched knob triggers a boot-time (re)load so a bad path fails
198
+ # here, not on the first request that needs a lookup.
199
+ #
200
+ # These deliberately live outside apply_privacy_knobs. That runs twice —
201
+ # once against a shallow config.dup for the dry-run validation — and a
202
+ # dup shares reader ivars with the original, so loading a database there
203
+ # would touch live state during what is supposed to be a rehearsal.
204
+ #
205
+ # @param config [Otto::Privacy::Config] the privacy config to mutate
206
+ # @param prefix [Symbol] :asn or :anonymizer, selecting the config members
207
+ # @api private
208
+ def apply_enrichment_signal(config, prefix, enabled, path, reader)
209
+ previous_enabled = config.public_send(:"#{prefix}_enabled")
210
+ config.public_send(:"#{prefix}_enabled=", enabled) unless enabled.nil?
211
+ source_replaced = replace_db_source?(config, prefix, path, reader)
212
+ config.public_send(:"load_#{prefix}_database!") if !source_replaced && [enabled, path, reader].any? { |v| !v.nil? }
213
+ rescue StandardError
214
+ # A path replacement is validated before it is committed, but restoring
215
+ # the enabled flag here also keeps a combined `enabled: ..., path: ...`
216
+ # call all-or-nothing when the replacement cannot be opened.
217
+ config.public_send(:"#{prefix}_enabled=", previous_enabled) unless previous_enabled.nil?
218
+ raise
219
+ end
220
+
221
+ # Reader-vs-path precedence for one enrichment signal, mirroring the geo
222
+ # branch in {#apply_geo_config}.
223
+ #
224
+ # @api private
225
+ def replace_db_source?(config, prefix, path, reader)
226
+ if !reader.nil?
227
+ config.public_send(:"#{prefix}_db_reader=", reader)
228
+ config.public_send(:"#{prefix}_db_path=", path) unless path.nil?
229
+ false
230
+ elsif !path.nil?
231
+ # Build the replacement before changing the active source. A failed
232
+ # path must leave the previous reader available for future requests.
233
+ config.replace_enrichment_database_path!(prefix, path)
234
+ true
235
+ else
236
+ false
237
+ end
238
+ end
187
239
  end
188
240
  end
189
241
  end
@@ -22,8 +22,8 @@ class Otto
22
22
  #
23
23
  class RedactedFingerprint
24
24
  attr_reader :session_id, :timestamp, :masked_ip, :hashed_ip,
25
- :country, :anonymized_ua, :request_path,
26
- :request_method, :referer
25
+ :country, :asn, :anonymizer, :anonymized_ua,
26
+ :request_path, :request_method, :referer
27
27
 
28
28
  # IP-bearing forwarded headers overwritten with the masked IP in the
29
29
  # geo-resolution env view. Mirrors the set
@@ -60,6 +60,17 @@ class Otto
60
60
  @country = if config.geo_enabled
61
61
  GeoResolver.resolve(@masked_ip, geo_env(env), config, headers_trusted: geo_headers_trusted)
62
62
  end
63
+ # ASN keeps the masked-IP contract: IPv4 routes are not announced longer
64
+ # than /24, so a masked address falls in the same announced prefix and
65
+ # therefore the same ASN.
66
+ @asn = AsnResolver.resolve(@masked_ip, config) if config.asn_enabled
67
+ # The anonymizer is the one lookup that gets the REAL address, for the
68
+ # same reason hashed_ip above does: masking would destroy the answer.
69
+ # Anonymizer databases list individual egress nodes at or near /32, so a
70
+ # /24-masked lookup would report on the node's neighbours instead of the
71
+ # node. Only the resulting label is retained — the address goes no
72
+ # further than the resolver, exactly as it goes no further than hash_ip.
73
+ @anonymizer = AnonymizerResolver.resolve(remote_ip, config) if config.anonymizer_enabled
63
74
  @anonymized_ua = anonymize_user_agent(env['HTTP_USER_AGENT'])
64
75
  @request_path = env['PATH_INFO']
65
76
  @request_method = env['REQUEST_METHOD']
@@ -78,6 +89,8 @@ class Otto
78
89
  masked_ip: @masked_ip,
79
90
  hashed_ip: @hashed_ip,
80
91
  country: @country,
92
+ asn: @asn,
93
+ anonymizer: @anonymizer,
81
94
  anonymized_ua: @anonymized_ua,
82
95
  request_method: @request_method,
83
96
  request_path: @request_path,
data/lib/otto/privacy.rb CHANGED
@@ -7,6 +7,8 @@ require_relative 'privacy/config'
7
7
  require_relative 'privacy/ip_privacy'
8
8
  require_relative 'privacy/user_agent_privacy'
9
9
  require_relative 'privacy/geo_resolver'
10
+ require_relative 'privacy/asn_resolver'
11
+ require_relative 'privacy/anonymizer_resolver'
10
12
  require_relative 'privacy/redacted_fingerprint'
11
13
 
12
14
  # Otto::Privacy module provides IP address anonymization and privacy features
@@ -21,6 +23,13 @@ require_relative 'privacy/redacted_fingerprint'
21
23
  # - Geo-location resolution (country-level only): a configurable trusted header,
22
24
  # built-in CDN provider headers, an optional local MaxMind-format (.mmdb)
23
25
  # database looked up on the masked IP, or a custom resolver
26
+ # - ASN resolution (opt-in, default off): the network operator an address
27
+ # belongs to, from a local .mmdb looked up on the masked IP. Database-only —
28
+ # no CDN publishes a client-ASN header worth trusting
29
+ # - Anonymizer classification (opt-in, default off): whether an address is a
30
+ # known Tor / VPN / proxy / hosting egress, from a local .mmdb. The only
31
+ # lookup that reads the unmasked address, because anonymizer data lists
32
+ # individual nodes at /32 — it returns a label, never the address
24
33
  # - User agent anonymization (removes version numbers)
25
34
  #
26
35
  # Privacy is ENABLED BY DEFAULT. To disable:
data/lib/otto/request.rb CHANGED
@@ -15,6 +15,8 @@ class Otto
15
15
  # def show(req, res)
16
16
  # req.masked_ip # Privacy-safe masked IP
17
17
  # req.geo_country # ISO country code
18
+ # req.asn # Network operator, when enabled
19
+ # req.anonymizer # Tor/VPN/proxy label, when enabled
18
20
  # req.check_locale! # Set locale for request
19
21
  # end
20
22
  #
@@ -63,6 +65,10 @@ class Otto
63
65
  # If you need the geo country:
64
66
  # req.geo_country # => 'US' or nil
65
67
  #
68
+ # If you need the opt-in enrichment signals (nil unless enabled):
69
+ # req.asn # => 'AS15169', '**', or nil
70
+ # req.anonymizer # => 'tor', 'none', '**', or nil
71
+ #
66
72
  # If you need the full privacy fingerprint:
67
73
  # req.redacted_fingerprint # => RedactedFingerprint object or nil
68
74
 
@@ -92,6 +98,39 @@ class Otto
92
98
  redacted_fingerprint&.country || env['otto.privacy.geo_country']
93
99
  end
94
100
 
101
+ # Get the Autonomous System Number of the client's network
102
+ #
103
+ # Opt-in: nil unless the operator enabled ASN resolution. '**' means it is
104
+ # enabled but nothing resolved — distinguishable from "switched off", which
105
+ # is what makes the three-state contract worth keeping.
106
+ #
107
+ # Read straight from env rather than through the fingerprint. The
108
+ # `fingerprint&.x || env[...]` idiom used above treats any falsey value as
109
+ # "fall through", which is wrong for a value whose vocabulary is fixed and
110
+ # whose absence is itself meaningful.
111
+ #
112
+ # @return [String, nil] 'AS15169', '**', or nil when disabled
113
+ # @example
114
+ # req.asn # => 'AS15169'
115
+ def asn
116
+ env['otto.privacy.asn']
117
+ end
118
+
119
+ # Get the anonymizing-egress classification for the client address
120
+ #
121
+ # Opt-in: nil unless the operator enabled classification. 'none' means the
122
+ # database was consulted and did not list the address; '**' means no
123
+ # database answered. Do not collapse the two — 'none' is evidence that the
124
+ # address is not a known egress, '**' is the absence of any evidence.
125
+ #
126
+ # @return [String, nil] 'tor', 'proxy', 'vpn', 'residential_proxy',
127
+ # 'hosting', 'anonymous', 'none', '**', or nil when disabled
128
+ # @example
129
+ # req.anonymizer # => 'tor'
130
+ def anonymizer
131
+ env['otto.privacy.anonymizer']
132
+ end
133
+
95
134
  # Get anonymized user agent string
96
135
  #
97
136
  # Returns user agent with version numbers stripped for privacy.
@@ -222,15 +222,17 @@ class Otto
222
222
 
223
223
  # CSP directives for the development environment.
224
224
  #
225
- # Development mode allows inline scripts/styles and hot reloading
226
- # connections for better developer experience with build tools like Vite.
225
+ # Development mode allows nonce-authorized inline scripts, inline styles,
226
+ # HTTP(S) scripts, and hot-reloading connections for build tools such as
227
+ # Vite. HTTP(S) script sources support both same-origin reverse proxies
228
+ # (for example Caddy) and direct local Vite servers on another port.
227
229
  #
228
230
  # @param nonce [String] nonce value injected into `script-src`
229
231
  # @return [Array<String>] directive strings, each terminated with `;`
230
232
  def development_directives(nonce)
231
233
  [
232
234
  "default-src 'none';",
233
- "script-src 'nonce-#{nonce}' 'unsafe-inline';", # Allow inline scripts for development tools
235
+ "script-src 'self' 'nonce-#{nonce}' http: https:;",
234
236
  "style-src 'self' 'unsafe-inline';",
235
237
  "connect-src 'self' ws: wss: http: https:;", # Allow HTTP and all WebSocket connections for dev tools
236
238
  "img-src 'self' data:;",
@@ -220,7 +220,8 @@ class Otto
220
220
  #
221
221
  # This early return also means NONE of the privacy fingerprint
222
222
  # values are produced for exempt IPs — no otto.privacy.fingerprint,
223
- # masked_ip, hashed_ip, geo_country, or correlation_hash. That is
223
+ # masked_ip, hashed_ip, geo_country, asn, anonymizer, or
224
+ # correlation_hash. That is
224
225
  # intentional and consistent: the correlation hash targets public
225
226
  # audit-trail traffic, so req.ip_correlation_hash is nil for
226
227
  # localhost / RFC-1918 addresses (the default dev path) even when a
@@ -251,6 +252,10 @@ class Otto
251
252
  env['otto.privacy.masked_ip'] = fingerprint.masked_ip
252
253
  env['otto.privacy.hashed_ip'] = fingerprint.hashed_ip
253
254
  env['otto.privacy.geo_country'] = fingerprint.country
255
+ # nil unless the operator opted in; '**' when enabled but
256
+ # unresolved, so a consumer can tell "off" from "no answer".
257
+ env['otto.privacy.asn'] = fingerprint.asn
258
+ env['otto.privacy.anonymizer'] = fingerprint.anonymizer
254
259
 
255
260
  # Fingerprint the FULL client IP here — while client_ip is still the
256
261
  # real address, before REMOTE_ADDR is masked below — so it identifies
data/lib/otto/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # frozen_string_literal: true
4
4
 
5
5
  class Otto
6
- VERSION = '2.8.0'
6
+ VERSION = '2.8.1'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: otto
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-08-07 00:00:00.000000000 Z
11
+ date: 2026-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -132,6 +132,7 @@ files:
132
132
  - ".reek.yml"
133
133
  - ".rspec"
134
134
  - ".rubocop.yml"
135
+ - ".rubocop_todo.yml"
135
136
  - ".yardopts"
136
137
  - AGENTS.md
137
138
  - CHANGELOG.rst
@@ -146,6 +147,7 @@ files:
146
147
  - docs/.gitignore
147
148
  - docs/1108-STREAMING_ARCHITECTURE_ANALYSIS.md
148
149
  - docs/1108-STREAMING_SUPPORT_SUMMARY.md
150
+ - docs/enrichment.md
149
151
  - docs/geo-country.md
150
152
  - docs/ipaddr-encoding-quirk.md
151
153
  - docs/migrating/v2.0.0-pre1.md
@@ -256,6 +258,8 @@ files:
256
258
  - lib/otto/mcp/schema_validation.rb
257
259
  - lib/otto/mcp/server.rb
258
260
  - lib/otto/privacy.rb
261
+ - lib/otto/privacy/anonymizer_resolver.rb
262
+ - lib/otto/privacy/asn_resolver.rb
259
263
  - lib/otto/privacy/config.rb
260
264
  - lib/otto/privacy/core.rb
261
265
  - lib/otto/privacy/geo_resolver.rb