dmarcator 1.6.0 → 1.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f6316c6ee6743dd6e2e1396726525bef87cdfbe95985c63b44b4da35d5b2d3e
4
- data.tar.gz: d0d1e9f677dc31b7ccbedf45d003805e9ecad3ad291ea98d9f058d8f7f9a2b1a
3
+ metadata.gz: 5178de3fecd90c8e0673b987d2727957dd347143506ff7bd07dfc429cf937589
4
+ data.tar.gz: 915ca7a2274a53bbf7d3cf5cc9b7f1c63e5ce9db7e57832464d6363db7732eea
5
5
  SHA512:
6
- metadata.gz: ad2f9c279435732be3148c6adf2e227c33df6bb1589e918f6567e606936afb992fb0d93ac5dc88d54b0d324bbdb1c4706d867b5470cc1d9d9577b33ddadb21a0
7
- data.tar.gz: 9ef713270c87bb56cebb484eff98d7d0098e6bab63fe3b937177b154cd67ec9cae8ce24ebb185b5eccb1579a6e64ad0b34270429d0b6c10efcf0b37785cecf56
6
+ metadata.gz: 0ab764769220fce1e649f6e7afff304d8da7e5a370d8b5107003d626ba587189674406bb609c752babd2fe36091d87f030fdf0b095bd373a7c76a9cb05650e58
7
+ data.tar.gz: da7d2435ca6627e4cc12d30aa8ddfc08aa457688527f33c004d5c5493cb116fb24bfe2b3443c03cd5f8b0eeab3f26e21d5c1ee55af78dd173956ca0caaf5bf07
data/ChangeLog.md CHANGED
@@ -1,3 +1,14 @@
1
+ ### 1.6.1 / 2026-11-21
2
+
3
+ * `Uri#to_str` is now defined on `DMARCator::Uri` and returns the same String as `Uri#to_s`, including the optional `!size` and unit. It was previously delegated to the wrapped `URI::MailTo`, so implicit String conversion (`Array#join`, `String#+`) silently dropped the size; `record.rua.join(',')` is now lossless. The contract spec gains `Uri#to_str`; no methods are removed.
4
+ * Freeze the `fo` entries of a parsed `Record`, and the default `fo` value, so the parsed record matches the immutability guarantee documented for 1.0.0.
5
+ * Stop retaining the raw report XML on `DMARCator::Report` after parsing. The input string (up to `max_report_bytes`) was held for the object's lifetime although it is never read again.
6
+ * Close the DoT TCP and SSL sockets when the TLS handshake fails; the sockets were only closed after a successful handshake, leaking a descriptor per failed connection.
7
+ * Only use records in a DNS answer whose owner name matches the queried name, and only follow a CNAME owned by it. A response could otherwise supply a record for a different name.
8
+ * Bound the DoH response body while streaming it, and reject an oversized declared `Content-Length` before reading. The size limit was previously checked only after the whole body had been buffered.
9
+ * Documentation: correct the `nokogiri` minimum (`>= 1.19.5`, not `1.10`), the record parse cost (~0.03 ms, not 0.4 ms), the per-series Ruby support wording, and the stale reference to a memoized parser and transform.
10
+ * CI: smoke-test the built gem so a packaging regression is caught before release.
11
+
1
12
  ### 1.6.0 / 2026-11-21
2
13
 
3
14
  * 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`.
data/README.md CHANGED
@@ -107,7 +107,7 @@ The lookup methods are named after what they return:
107
107
  | `DMARCator.txt_records(name)` | `Array<Resolv::DNS::Resource::IN::TXT>` — the records themselves | one lookup |
108
108
  | `DMARCator.txt(name)` | `Array<String>` — every TXT record at `name` | one lookup |
109
109
  | `DMARCator.dmarc(domain)` | `String` — the DMARC record text, or `nil` | one lookup |
110
- | `DMARCator::Record.lookup(domain)` | `Record` — parsed | one lookup + parse (~0.4 ms) |
110
+ | `DMARCator::Record.lookup(domain)` | `Record` — parsed | one lookup + parse (~0.03 ms) |
111
111
  | `DMARCator::Record.parse(text)` | `Record` — parsed from a string | parse only |
112
112
 
113
113
  `DMARCator.txt` is the primitive: unfiltered, in response order, multi-chunk
@@ -176,8 +176,8 @@ domains.each do |domain|
176
176
  end
177
177
  ```
178
178
 
179
- Notes for large scans: `Record.lookup` adds a parse per domain (~0.4 ms, far
180
- more than the lookup on a fast resolver); each lookup opens its own TCP
179
+ Notes for large scans: `Record.lookup` adds a parse per domain (~0.03 ms,
180
+ negligible next to the lookup); each lookup opens its own TCP
181
181
  connection, so keep one resolver per thread when parallelising; and DoT/DoH add
182
182
  a TLS handshake per lookup, so plaintext is the better choice for bulk work.
183
183
 
@@ -322,7 +322,8 @@ XML helper, the internal resolver plumbing — may change in a minor release.
322
322
 
323
323
  * `DMARCator::Record`, `DMARCator::Report` and the parsed value objects are
324
324
  read-only after construction and safe to share between threads.
325
- * The memoized parser and transform are shared, and safe for concurrent use.
325
+ * Record parsing and XML report parsing keep no shared mutable state, so both
326
+ are safe for concurrent use.
326
327
  * Resolvers are not necessarily safe for concurrent lookups: each lookup opens
327
328
  its own connection, but `Resolv::DNS` (if you inject one) does not serialise
328
329
  queries. Use one resolver per thread, or configure a factory with
@@ -338,11 +339,11 @@ removed in the next major release.
338
339
 
339
340
  ### Ruby support
340
341
 
341
- The minimum is Ruby 3.3.14, which includes the regular expression fixes the
342
- library requires. The supported minima per series are 3.3.14, 3.4.13, and
343
- 4.0.10. Dropping support for a Ruby series is
344
- the one documented exception to the no-breaking-changes promise: it is announced
345
- in a minor release and removed in the next major.
342
+ The gemspec requires Ruby >= 3.3.14, which includes the regular expression
343
+ fixes the library uses. CI tests the oldest supported patch of each series:
344
+ 3.3.14, 3.4.13, and 4.0.10. Dropping support for a Ruby series is the one
345
+ documented exception to the no-breaking-changes promise: it is announced in a
346
+ minor release and removed in the next major.
346
347
 
347
348
  ## Security
348
349
 
@@ -397,7 +398,7 @@ for the reporting policy and scope.
397
398
  ## Requirements
398
399
 
399
400
  * [Ruby] >= 3.3.14
400
- * [nokogiri] >= 1.10
401
+ * [nokogiri] >= 1.19.5
401
402
 
402
403
  ## Testing
403
404
 
@@ -69,9 +69,10 @@ module DMARCator
69
69
  #
70
70
  # Validates a domain before using it in a DNS query.
71
71
  #
72
- # Rejects underscores and reserves room for the `_dmarc.` prefix, so this is
73
- # the validator for registrable domains rather than arbitrary DNS names.
74
- # Use {validate_txt_name} for service labels.
72
+ # Rejects underscores and enforces the DNS length and label limits, so this
73
+ # is the validator for registrable domains rather than arbitrary DNS names.
74
+ # {dmarc} adds the `_dmarc.` prefix; use {validate_txt_name} for service
75
+ # labels.
75
76
  #
76
77
  # @param [String] domain
77
78
  # The domain to validate.
@@ -34,6 +34,10 @@ module DMARCator
34
34
  # @return [:DMARC1]
35
35
  attr_reader :v
36
36
 
37
+ # Default value of the `fo=` field.
38
+ DEFAULT_FO = %w[0].freeze
39
+ private_constant :DEFAULT_FO
40
+
37
41
  #
38
42
  # Initializes the record.
39
43
  #
@@ -66,7 +70,7 @@ module DMARCator
66
70
  @v = attributes.fetch(:v)
67
71
  @adkim = attributes[:adkim]
68
72
  @aspf = attributes[:aspf]
69
- @fo = attributes[:fo]&.freeze
73
+ @fo = attributes[:fo]&.map(&:freeze)&.freeze
70
74
  @p = attributes[:p]
71
75
  @pct = attributes[:pct]
72
76
  @rf = attributes[:rf]
@@ -157,7 +161,7 @@ module DMARCator
157
161
  # The value of the `fo=` field, or `["0"]` if the field was omitted.
158
162
  #
159
163
  def fo
160
- @fo || %w[0]
164
+ @fo || DEFAULT_FO
161
165
  end
162
166
 
163
167
  #
@@ -74,8 +74,6 @@ module DMARCator
74
74
  raise InvalidReport, "DMARC XML report must be a String, got #{xml.class}"
75
75
  end
76
76
 
77
- @xml = xml
78
-
79
77
  limit = DMARCator.config.max_report_bytes
80
78
 
81
79
  if xml.bytesize > limit
@@ -102,25 +102,40 @@ module DMARCator
102
102
  request['accept'] = CONTENT_TYPE
103
103
  request.body = query.encode
104
104
 
105
- response = http.start { |connection| connection.request(request) }
106
-
107
- status = response.code.to_i
108
-
109
- unless status.between?(200, 299)
110
- raise ResolutionError, "DoH endpoint returned HTTP #{status}"
111
- end
112
-
113
- content_type = response['content-type'].to_s
114
-
115
- unless content_type.start_with?(CONTENT_TYPE)
116
- raise ResolutionError, "DoH endpoint returned unexpected content-type: #{content_type.inspect}"
117
- end
118
-
119
- body = response.body.to_s.b
120
-
121
- if body.bytesize > MAX_RESPONSE_BYTES
122
- raise ResolutionError,
123
- "DoH response exceeds maximum size of #{MAX_RESPONSE_BYTES} bytes"
105
+ body = +''.b
106
+
107
+ http.start do |connection|
108
+ connection.request(request) do |response|
109
+ status = response.code.to_i
110
+
111
+ unless status.between?(200, 299)
112
+ raise ResolutionError, "DoH endpoint returned HTTP #{status}"
113
+ end
114
+
115
+ content_type = response['content-type'].to_s
116
+
117
+ unless content_type.start_with?(CONTENT_TYPE)
118
+ raise ResolutionError,
119
+ "DoH endpoint returned unexpected content-type: #{content_type.inspect}"
120
+ end
121
+
122
+ # Reject a declared oversize before reading anything, then enforce
123
+ # the same bound while streaming, so a chunked or lying response
124
+ # cannot allocate more than the limit.
125
+ if response['content-length'].to_i > MAX_RESPONSE_BYTES
126
+ raise ResolutionError,
127
+ "DoH response exceeds maximum size of #{MAX_RESPONSE_BYTES} bytes"
128
+ end
129
+
130
+ response.read_body do |chunk|
131
+ body << chunk.b
132
+
133
+ if body.bytesize > MAX_RESPONSE_BYTES
134
+ raise ResolutionError,
135
+ "DoH response exceeds maximum size of #{MAX_RESPONSE_BYTES} bytes"
136
+ end
137
+ end
138
+ end
124
139
  end
125
140
 
126
141
  body
@@ -125,22 +125,24 @@ module DMARCator
125
125
 
126
126
  def with_tls
127
127
  tcp = Socket.tcp(@host, @port, connect_timeout: @timeout)
128
- tcp.timeout = @timeout if tcp.respond_to?(:timeout=)
128
+ socket = nil
129
129
 
130
- context = OpenSSL::SSL::SSLContext.new
131
- context.verify_mode = OpenSSL::SSL::VERIFY_PEER
132
- context.set_params
130
+ begin
131
+ tcp.timeout = @timeout if tcp.respond_to?(:timeout=)
133
132
 
134
- socket = OpenSSL::SSL::SSLSocket.new(tcp, context)
135
- socket.hostname = @sni unless ip_literal?(@sni)
136
- socket.sync_close = true
137
- socket.connect
138
- socket.post_connection_check(@sni)
133
+ context = OpenSSL::SSL::SSLContext.new
134
+ context.verify_mode = OpenSSL::SSL::VERIFY_PEER
135
+ context.set_params
136
+
137
+ socket = OpenSSL::SSL::SSLSocket.new(tcp, context)
138
+ socket.hostname = @sni unless ip_literal?(@sni)
139
+ socket.sync_close = true
140
+ socket.connect
141
+ socket.post_connection_check(@sni)
139
142
 
140
- begin
141
143
  yield socket
142
144
  ensure
143
- close_quietly(socket)
145
+ close_quietly(socket) if socket
144
146
  close_quietly(tcp)
145
147
  end
146
148
  end
@@ -69,11 +69,17 @@ module DMARCator
69
69
  end
70
70
 
71
71
  def collect(message, name, type, depth)
72
- matching = message.answer.select { |_name, _ttl, record| record.is_a?(type) }
72
+ # Only answers owned by the queried name are usable: a response may
73
+ # carry records for other owners (an injected CNAME chain, or a
74
+ # malicious answer), and accepting them would let the transport return
75
+ # a record for a different name.
76
+ matching = message.answer.select do |owner, _ttl, record|
77
+ record.is_a?(type) && same_name?(owner, name)
78
+ end
73
79
  return matching.map { |_name, _ttl, record| record } unless matching.empty?
74
80
 
75
- cname = message.answer.find do |_name, _ttl, record|
76
- record.is_a?(Resolv::DNS::Resource::IN::CNAME)
81
+ cname = message.answer.find do |owner, _ttl, record|
82
+ record.is_a?(Resolv::DNS::Resource::IN::CNAME) && same_name?(owner, name)
77
83
  end
78
84
 
79
85
  return fetch(cname[2].name, type, depth - 1) if cname && depth.positive?
data/lib/dmarcator/uri.rb CHANGED
@@ -115,6 +115,21 @@ module DMARCator
115
115
  return str
116
116
  end
117
117
 
118
+ #
119
+ # Converts the DMARC URI into a String.
120
+ #
121
+ # Same as {#to_s}. It is defined so implicit String conversion, such as
122
+ # `Array#join` or `String#+`, keeps the optional size and unit instead of
123
+ # falling through to the wrapped URI.
124
+ #
125
+ # @return [String]
126
+ #
127
+ # @since 1.6.1
128
+ #
129
+ def to_str
130
+ to_s
131
+ end
132
+
118
133
  private
119
134
 
120
135
  #
@@ -2,5 +2,5 @@
2
2
 
3
3
  module DMARCator
4
4
  # dmarcator version
5
- VERSION = '1.6.0'
5
+ VERSION = '1.6.1'
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.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Berman