dmarcator 1.5.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 +4 -4
- data/ChangeLog.md +20 -0
- data/README.md +22 -15
- data/lib/dmarcator/config.rb +6 -1
- data/lib/dmarcator/query.rb +65 -9
- data/lib/dmarcator/record.rb +8 -4
- data/lib/dmarcator/report/metadata.rb +6 -0
- data/lib/dmarcator/report.rb +0 -2
- data/lib/dmarcator/resolver/doh.rb +34 -19
- data/lib/dmarcator/resolver/dot.rb +13 -11
- data/lib/dmarcator/resolver/encrypted.rb +14 -4
- data/lib/dmarcator/uri.rb +15 -0
- data/lib/dmarcator/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: 5178de3fecd90c8e0673b987d2727957dd347143506ff7bd07dfc429cf937589
|
|
4
|
+
data.tar.gz: 915ca7a2274a53bbf7d3cf5cc9b7f1c63e5ce9db7e57832464d6363db7732eea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0ab764769220fce1e649f6e7afff304d8da7e5a370d8b5107003d626ba587189674406bb609c752babd2fe36091d87f030fdf0b095bd373a7c76a9cb05650e58
|
|
7
|
+
data.tar.gz: da7d2435ca6627e4cc12d30aa8ddfc08aa457688527f33c004d5c5493cb116fb24bfe2b3443c03cd5f8b0eeab3f26e21d5c1ee55af78dd173956ca0caaf5bf07
|
data/ChangeLog.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
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
|
+
|
|
12
|
+
### 1.6.0 / 2026-11-21
|
|
13
|
+
|
|
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`.
|
|
15
|
+
* `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.
|
|
16
|
+
* `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`.
|
|
17
|
+
* DNS transaction IDs are drawn from `SecureRandom` rather than `Random`, removing a predictable ID from the plaintext TCP transport.
|
|
18
|
+
|
|
19
|
+
No public API changes.
|
|
20
|
+
|
|
1
21
|
### 1.5.0 / 2026-11-19
|
|
2
22
|
|
|
3
23
|
* 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
|
@@ -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.
|
|
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
|
|
@@ -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")
|
|
@@ -172,8 +176,8 @@ domains.each do |domain|
|
|
|
172
176
|
end
|
|
173
177
|
```
|
|
174
178
|
|
|
175
|
-
Notes for large scans: `Record.lookup` adds a parse per domain (~0.
|
|
176
|
-
|
|
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
|
|
177
181
|
connection, so keep one resolver per thread when parallelising; and DoT/DoH add
|
|
178
182
|
a TLS handshake per lookup, so plaintext is the better choice for bulk work.
|
|
179
183
|
|
|
@@ -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
|
|
296
|
-
`Resolv`
|
|
297
|
-
|
|
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
|
|
|
@@ -316,7 +322,8 @@ XML helper, the internal resolver plumbing — may change in a minor release.
|
|
|
316
322
|
|
|
317
323
|
* `DMARCator::Record`, `DMARCator::Report` and the parsed value objects are
|
|
318
324
|
read-only after construction and safe to share between threads.
|
|
319
|
-
*
|
|
325
|
+
* Record parsing and XML report parsing keep no shared mutable state, so both
|
|
326
|
+
are safe for concurrent use.
|
|
320
327
|
* Resolvers are not necessarily safe for concurrent lookups: each lookup opens
|
|
321
328
|
its own connection, but `Resolv::DNS` (if you inject one) does not serialise
|
|
322
329
|
queries. Use one resolver per thread, or configure a factory with
|
|
@@ -332,11 +339,11 @@ removed in the next major release.
|
|
|
332
339
|
|
|
333
340
|
### Ruby support
|
|
334
341
|
|
|
335
|
-
The
|
|
336
|
-
library
|
|
337
|
-
4.0.10. Dropping support for a Ruby series is
|
|
338
|
-
|
|
339
|
-
|
|
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.
|
|
340
347
|
|
|
341
348
|
## Security
|
|
342
349
|
|
|
@@ -391,7 +398,7 @@ for the reporting policy and scope.
|
|
|
391
398
|
## Requirements
|
|
392
399
|
|
|
393
400
|
* [Ruby] >= 3.3.14
|
|
394
|
-
* [nokogiri] >= 1.
|
|
401
|
+
* [nokogiri] >= 1.19.5
|
|
395
402
|
|
|
396
403
|
## Testing
|
|
397
404
|
|
data/lib/dmarcator/config.rb
CHANGED
|
@@ -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
|
data/lib/dmarcator/query.rb
CHANGED
|
@@ -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
|
|
73
|
-
# the validator for registrable domains rather than arbitrary DNS names.
|
|
74
|
-
#
|
|
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.
|
|
@@ -174,7 +175,8 @@ module DMARCator
|
|
|
174
175
|
# blocked or degraded resolver cannot be mistaken for an absent record.
|
|
175
176
|
#
|
|
176
177
|
# @raise [ArgumentError]
|
|
177
|
-
# The name is not a syntactically valid DNS name
|
|
178
|
+
# The name is not a syntactically valid DNS name, or the injected
|
|
179
|
+
# resolver would report a timeout as an absent record.
|
|
178
180
|
#
|
|
179
181
|
# @note Names must be ASCII: pass punycode (A-labels) rather than Unicode.
|
|
180
182
|
#
|
|
@@ -207,7 +209,8 @@ module DMARCator
|
|
|
207
209
|
# The lookup failed. A failure is never reported as an empty result.
|
|
208
210
|
#
|
|
209
211
|
# @raise [ArgumentError]
|
|
210
|
-
# The name is not a syntactically valid DNS name
|
|
212
|
+
# The name is not a syntactically valid DNS name, or the injected
|
|
213
|
+
# resolver would report a timeout as an absent record.
|
|
211
214
|
#
|
|
212
215
|
# @note Names must be ASCII: pass punycode (A-labels) rather than Unicode.
|
|
213
216
|
#
|
|
@@ -238,7 +241,8 @@ module DMARCator
|
|
|
238
241
|
# The lookup failed.
|
|
239
242
|
#
|
|
240
243
|
# @raise [ArgumentError]
|
|
241
|
-
# The domain is not a syntactically valid DNS name
|
|
244
|
+
# The domain is not a syntactically valid DNS name, or the injected
|
|
245
|
+
# resolver would report a timeout as an absent record.
|
|
242
246
|
#
|
|
243
247
|
# @since 0.8.0
|
|
244
248
|
#
|
|
@@ -272,9 +276,11 @@ module DMARCator
|
|
|
272
276
|
# @api private
|
|
273
277
|
#
|
|
274
278
|
def self.lookup_txt(name, resolver:)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
#
|
|
279
|
+
ensure_fail_closed!(resolver)
|
|
280
|
+
|
|
281
|
+
# With a fail-closed resolver, Resolv returns an empty result for NXDOMAIN
|
|
282
|
+
# and raises for timeouts and other failures, so any exception here is a
|
|
283
|
+
# transport failure, not an absent record.
|
|
278
284
|
begin
|
|
279
285
|
records = resolver.getresources(name, Resolv::DNS::Resource::IN::TXT)
|
|
280
286
|
rescue Resolv::ResolvError => error
|
|
@@ -284,6 +290,56 @@ module DMARCator
|
|
|
284
290
|
records
|
|
285
291
|
end
|
|
286
292
|
private_class_method :lookup_txt
|
|
293
|
+
|
|
294
|
+
#
|
|
295
|
+
# Determines whether a resolver reports a timeout instead of returning an
|
|
296
|
+
# empty answer.
|
|
297
|
+
#
|
|
298
|
+
# `Resolv::DNS` treats a complete timeout as an empty answer unless it was
|
|
299
|
+
# constructed with `raise_timeout_errors: true`. The flag is only settable
|
|
300
|
+
# through the constructor and `Resolv` exposes no reader for it, so it is
|
|
301
|
+
# read from the retained configuration.
|
|
302
|
+
#
|
|
303
|
+
# @param [Object] resolver
|
|
304
|
+
#
|
|
305
|
+
# @return [Boolean]
|
|
306
|
+
#
|
|
307
|
+
# @api private
|
|
308
|
+
#
|
|
309
|
+
def self.resolv_fails_closed?(resolver)
|
|
310
|
+
return true unless resolver.is_a?(Resolv::DNS)
|
|
311
|
+
|
|
312
|
+
config = resolver.instance_variable_get(:@config)
|
|
313
|
+
return false unless config
|
|
314
|
+
|
|
315
|
+
info = config.instance_variable_get(:@config_info)
|
|
316
|
+
return false unless info.is_a?(Hash)
|
|
317
|
+
|
|
318
|
+
!!info[:raise_timeout_errors]
|
|
319
|
+
end
|
|
320
|
+
private_class_method :resolv_fails_closed?
|
|
321
|
+
|
|
322
|
+
#
|
|
323
|
+
# Rejects a resolver that would report a failed lookup as an absent record.
|
|
324
|
+
#
|
|
325
|
+
# @param [Object] resolver
|
|
326
|
+
#
|
|
327
|
+
# @raise [ArgumentError]
|
|
328
|
+
# The resolver is a `Resolv::DNS` that does not raise on timeout.
|
|
329
|
+
#
|
|
330
|
+
# @api private
|
|
331
|
+
#
|
|
332
|
+
def self.ensure_fail_closed!(resolver)
|
|
333
|
+
return if resolv_fails_closed?(resolver)
|
|
334
|
+
|
|
335
|
+
raise ArgumentError,
|
|
336
|
+
'a Resolv::DNS resolver swallows timeout errors unless constructed ' \
|
|
337
|
+
'with raise_timeout_errors: true, so a failed lookup cannot be ' \
|
|
338
|
+
'distinguished from a name with no records; use ' \
|
|
339
|
+
'Resolv::DNS.new(raise_timeout_errors: true) or ' \
|
|
340
|
+
'DMARCator::Resolver::Plain'
|
|
341
|
+
end
|
|
342
|
+
private_class_method :ensure_fail_closed!
|
|
287
343
|
end
|
|
288
344
|
|
|
289
345
|
if DMARCator.vulnerable_resolv?
|
data/lib/dmarcator/record.rb
CHANGED
|
@@ -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 ||
|
|
164
|
+
@fo || DEFAULT_FO
|
|
161
165
|
end
|
|
162
166
|
|
|
163
167
|
#
|
|
@@ -353,8 +357,8 @@ module DMARCator
|
|
|
353
357
|
tags << "v=#{@v}" if @v
|
|
354
358
|
tags << "p=#{@p}" if @p
|
|
355
359
|
tags << "sp=#{@sp}" if @sp
|
|
356
|
-
tags << "rua=#{@rua.join(',')}" if @rua
|
|
357
|
-
tags << "ruf=#{@ruf.join(',')}" if @ruf
|
|
360
|
+
tags << "rua=#{@rua.map(&:to_s).join(',')}" if @rua
|
|
361
|
+
tags << "ruf=#{@ruf.map(&:to_s).join(',')}" if @ruf
|
|
358
362
|
tags << "adkim=#{@adkim}" if @adkim
|
|
359
363
|
tags << "aspf=#{@aspf}" if @aspf
|
|
360
364
|
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'
|
data/lib/dmarcator/report.rb
CHANGED
|
@@ -102,25 +102,40 @@ module DMARCator
|
|
|
102
102
|
request['accept'] = CONTENT_TYPE
|
|
103
103
|
request.body = query.encode
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
128
|
+
socket = nil
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
context.set_params
|
|
130
|
+
begin
|
|
131
|
+
tcp.timeout = @timeout if tcp.respond_to?(:timeout=)
|
|
133
132
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
|
@@ -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
|
-
|
|
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
|
|
@@ -65,11 +69,17 @@ module DMARCator
|
|
|
65
69
|
end
|
|
66
70
|
|
|
67
71
|
def collect(message, name, type, depth)
|
|
68
|
-
|
|
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
|
|
69
79
|
return matching.map { |_name, _ttl, record| record } unless matching.empty?
|
|
70
80
|
|
|
71
|
-
cname = message.answer.find do |
|
|
72
|
-
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)
|
|
73
83
|
end
|
|
74
84
|
|
|
75
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
|
#
|
data/lib/dmarcator/version.rb
CHANGED