dmarcator 1.5.0 → 1.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ecce36658f08d30cc4e1e69eaf360788d9069c1d794d00c982d741857ce747b
4
- data.tar.gz: 07f8a0bfd8407cf65b258e5d5818044173e32833059fce498bee3c085b6dd11b
3
+ metadata.gz: 9f6316c6ee6743dd6e2e1396726525bef87cdfbe95985c63b44b4da35d5b2d3e
4
+ data.tar.gz: d0d1e9f677dc31b7ccbedf45d003805e9ecad3ad291ea98d9f058d8f7f9a2b1a
5
5
  SHA512:
6
- metadata.gz: 27e8344822dfe386d257fc4415a69d263124fb660341e8b7d6febf0a9a7967cd04052d788cd7fdcbc4e7e7914351bbd84349c67e13ba745553dfe3c12300ec1c
7
- data.tar.gz: 73bd01f7e081f19e24577c63663e3a19a1d6ed02d31ad2e64619d5b2a9848e0b32a69f8b5a9600d75106ada6e376e8f2319a6cda21d5050c994a3dd1bbafaecb
6
+ metadata.gz: ad2f9c279435732be3148c6adf2e227c33df6bb1589e918f6567e606936afb992fb0d93ac5dc88d54b0d324bbdb1c4706d867b5470cc1d9d9577b33ddadb21a0
7
+ data.tar.gz: 9ef713270c87bb56cebb484eff98d7d0098e6bab63fe3b937177b154cd67ec9cae8ce24ebb185b5eccb1579a6e64ad0b34270429d0b6c10efcf0b37785cecf56
data/ChangeLog.md CHANGED
@@ -1,3 +1,12 @@
1
+ ### 1.6.0 / 2026-11-21
2
+
3
+ * Reject an injected `Resolv::DNS` that was not constructed with `raise_timeout_errors: true`. By default `Resolv` treats a complete timeout as an empty answer, so a failed lookup was indistinguishable from a name with no records, contradicting the documented fail-closed guarantee. Construct the resolver with `Resolv::DNS.new(raise_timeout_errors: true)`, or use `DMARCator::Resolver::Plain`. This is a behaviour change for callers that inject a bare `Resolv::DNS`.
4
+ * `Record#to_s` preserves the optional `!size` and unit of `rua`/`ruf` URIs. `Array#join` preferred the delegated `to_str`, which returned the bare `mailto:` URI, so serializing a record silently dropped its report-size limits.
5
+ * `Report#metadata` returns an empty `Report::Metadata` when `<report_metadata>` is absent instead of raising `NoMethodError`. `report_metadata` is required by the DMARC schema, but the XML guard only enforces the `<feedback>` root, so a report could omit it and crash the accessor with an error outside `DMARCator::Error`.
6
+ * DNS transaction IDs are drawn from `SecureRandom` rather than `Random`, removing a predictable ID from the plaintext TCP transport.
7
+
8
+ No public API changes.
9
+
1
10
  ### 1.5.0 / 2026-11-19
2
11
 
3
12
  * Require Ruby >= 3.3.14. The supported minima per series are 3.3.14, 3.4.13, and 4.0.10; CI now tests each minimum instead of 3.3.13 plus latest 4.0.
data/README.md CHANGED
@@ -149,7 +149,11 @@ end
149
149
  ```
150
150
 
151
151
  All of these accept an injected resolver, and an injected resolver keeps its
152
- own configuration (timeouts are only applied to resolvers the library builds):
152
+ own configuration (timeouts are only applied to resolvers the library builds).
153
+ A `Resolv::DNS` must be constructed with `raise_timeout_errors: true`: without
154
+ it, `Resolv` treats a complete timeout as an empty answer, and the lookup would
155
+ be indistinguishable from one for a name with no records. The lookup methods
156
+ reject such a resolver with `ArgumentError` rather than report a false negative.
153
157
 
154
158
  ```ruby
155
159
  resolver = DMARCator::Resolver::DoH.new(url: "https://dns.example/dns-query")
@@ -219,7 +223,7 @@ configure a factory instead:
219
223
 
220
224
  ```ruby
221
225
  DMARCator.configure do |config|
222
- config.resolver = -> { Resolv::DNS.new }
226
+ config.resolver = -> { Resolv::DNS.new(raise_timeout_errors: true) }
223
227
  end
224
228
  ```
225
229
 
@@ -292,9 +296,11 @@ failures raise `DMARCator::ResolutionError`.
292
296
 
293
297
  Encrypted transports fail closed: a transport failure raises
294
298
  `DMARCator::ResolutionError` instead of being reported as a domain without a
295
- DMARC record. This applies to every transport, including plaintext —
296
- `Resolv` returns an empty result for NXDOMAIN and raises for timeouts and
297
- other failures, so a failed lookup is never mistaken for an absent record.
299
+ DMARC record. This applies to every transport the library builds, including
300
+ plaintext. An injected `Resolv::DNS` is the one exception: by default it treats
301
+ a complete timeout as an empty answer, so construct it with
302
+ `raise_timeout_errors: true` — the lookup methods reject one that does not,
303
+ rather than mistake a failed lookup for an absent record.
298
304
  Plaintext remains the default because forcing a public resolver breaks private
299
305
  and split-horizon zones, and some networks block port 853 or public resolvers.
300
306
 
@@ -72,6 +72,11 @@ module DMARCator
72
72
  # resolver object is shared by every thread, and `Resolv::DNS` does not
73
73
  # serialise concurrent lookups.
74
74
  #
75
+ # A `Resolv::DNS` must be constructed with `raise_timeout_errors: true`;
76
+ # otherwise it reports a timeout as an empty answer, and a lookup will
77
+ # reject it with `ArgumentError` rather than mistake a failure for an
78
+ # absent record.
79
+ #
75
80
  # @return [Object, #call, nil]
76
81
  #
77
82
  attr_accessor :resolver
@@ -194,7 +199,7 @@ module DMARCator
194
199
  # Configures process-wide defaults.
195
200
  #
196
201
  # DMARCator.configure do |config|
197
- # config.resolver = -> { Resolv::DNS.new }
202
+ # config.resolver = -> { Resolv::DNS.new(raise_timeout_errors: true) }
198
203
  # end
199
204
  #
200
205
  # When set, a configured resolver takes precedence over `DMARCATOR_DNS` and
@@ -174,7 +174,8 @@ module DMARCator
174
174
  # blocked or degraded resolver cannot be mistaken for an absent record.
175
175
  #
176
176
  # @raise [ArgumentError]
177
- # The name is not a syntactically valid DNS name.
177
+ # The name is not a syntactically valid DNS name, or the injected
178
+ # resolver would report a timeout as an absent record.
178
179
  #
179
180
  # @note Names must be ASCII: pass punycode (A-labels) rather than Unicode.
180
181
  #
@@ -207,7 +208,8 @@ module DMARCator
207
208
  # The lookup failed. A failure is never reported as an empty result.
208
209
  #
209
210
  # @raise [ArgumentError]
210
- # The name is not a syntactically valid DNS name.
211
+ # The name is not a syntactically valid DNS name, or the injected
212
+ # resolver would report a timeout as an absent record.
211
213
  #
212
214
  # @note Names must be ASCII: pass punycode (A-labels) rather than Unicode.
213
215
  #
@@ -238,7 +240,8 @@ module DMARCator
238
240
  # The lookup failed.
239
241
  #
240
242
  # @raise [ArgumentError]
241
- # The domain is not a syntactically valid DNS name.
243
+ # The domain is not a syntactically valid DNS name, or the injected
244
+ # resolver would report a timeout as an absent record.
242
245
  #
243
246
  # @since 0.8.0
244
247
  #
@@ -272,9 +275,11 @@ module DMARCator
272
275
  # @api private
273
276
  #
274
277
  def self.lookup_txt(name, resolver:)
275
- # Resolv returns an empty result for NXDOMAIN and raises for timeouts and
276
- # other failures, so any exception here is a transport failure, not an
277
- # absent record.
278
+ ensure_fail_closed!(resolver)
279
+
280
+ # With a fail-closed resolver, Resolv returns an empty result for NXDOMAIN
281
+ # and raises for timeouts and other failures, so any exception here is a
282
+ # transport failure, not an absent record.
278
283
  begin
279
284
  records = resolver.getresources(name, Resolv::DNS::Resource::IN::TXT)
280
285
  rescue Resolv::ResolvError => error
@@ -284,6 +289,56 @@ module DMARCator
284
289
  records
285
290
  end
286
291
  private_class_method :lookup_txt
292
+
293
+ #
294
+ # Determines whether a resolver reports a timeout instead of returning an
295
+ # empty answer.
296
+ #
297
+ # `Resolv::DNS` treats a complete timeout as an empty answer unless it was
298
+ # constructed with `raise_timeout_errors: true`. The flag is only settable
299
+ # through the constructor and `Resolv` exposes no reader for it, so it is
300
+ # read from the retained configuration.
301
+ #
302
+ # @param [Object] resolver
303
+ #
304
+ # @return [Boolean]
305
+ #
306
+ # @api private
307
+ #
308
+ def self.resolv_fails_closed?(resolver)
309
+ return true unless resolver.is_a?(Resolv::DNS)
310
+
311
+ config = resolver.instance_variable_get(:@config)
312
+ return false unless config
313
+
314
+ info = config.instance_variable_get(:@config_info)
315
+ return false unless info.is_a?(Hash)
316
+
317
+ !!info[:raise_timeout_errors]
318
+ end
319
+ private_class_method :resolv_fails_closed?
320
+
321
+ #
322
+ # Rejects a resolver that would report a failed lookup as an absent record.
323
+ #
324
+ # @param [Object] resolver
325
+ #
326
+ # @raise [ArgumentError]
327
+ # The resolver is a `Resolv::DNS` that does not raise on timeout.
328
+ #
329
+ # @api private
330
+ #
331
+ def self.ensure_fail_closed!(resolver)
332
+ return if resolv_fails_closed?(resolver)
333
+
334
+ raise ArgumentError,
335
+ 'a Resolv::DNS resolver swallows timeout errors unless constructed ' \
336
+ 'with raise_timeout_errors: true, so a failed lookup cannot be ' \
337
+ 'distinguished from a name with no records; use ' \
338
+ 'Resolv::DNS.new(raise_timeout_errors: true) or ' \
339
+ 'DMARCator::Resolver::Plain'
340
+ end
341
+ private_class_method :ensure_fail_closed!
287
342
  end
288
343
 
289
344
  if DMARCator.vulnerable_resolv?
@@ -353,8 +353,8 @@ module DMARCator
353
353
  tags << "v=#{@v}" if @v
354
354
  tags << "p=#{@p}" if @p
355
355
  tags << "sp=#{@sp}" if @sp
356
- tags << "rua=#{@rua.join(',')}" if @rua
357
- tags << "ruf=#{@ruf.join(',')}" if @ruf
356
+ tags << "rua=#{@rua.map(&:to_s).join(',')}" if @rua
357
+ tags << "ruf=#{@ruf.map(&:to_s).join(',')}" if @ruf
358
358
  tags << "adkim=#{@adkim}" if @adkim
359
359
  tags << "aspf=#{@aspf}" if @aspf
360
360
  tags << "ri=#{@ri}" if @ri
@@ -38,6 +38,12 @@ module DMARCator
38
38
 
39
39
  metadata = node.at_xpath('feedback/report_metadata')
40
40
 
41
+ # `report_metadata` is required by the DMARC schema, but the XML guard
42
+ # only enforces the `<feedback>` root, so an attacker-supplied report can
43
+ # omit it. Treat it like a missing `policy_published` rather than
44
+ # raising NoMethodError out of a public accessor.
45
+ return unless metadata
46
+
41
47
  metadata.element_children.each do |element|
42
48
  case element.name
43
49
  when 'org_name'
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'resolv'
4
+ require 'securerandom'
4
5
 
5
6
  require_relative '../exceptions'
6
7
 
@@ -51,7 +52,10 @@ module DMARCator
51
52
  end
52
53
 
53
54
  def fetch(name, type, depth)
54
- id = Random.rand(0x10000)
55
+ # A predictable transaction ID would let an off-path attacker guess the
56
+ # query before it is answered. Over TLS this is already unreachable, but
57
+ # the plaintext TCP transport shares this code path.
58
+ id = SecureRandom.random_number(0x10000)
55
59
  message = decode_response(exchange(build_query(id, name, type)), id, name, type)
56
60
 
57
61
  case message.rcode
@@ -2,5 +2,5 @@
2
2
 
3
3
  module DMARCator
4
4
  # dmarcator version
5
- VERSION = '1.5.0'
5
+ VERSION = '1.6.0'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dmarcator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Berman