dmarcator 1.6.1 → 1.7.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 +23 -0
- data/README.md +5 -1
- data/lib/dmarcator/internal/parser.rb +37 -11
- data/lib/dmarcator/internal/xml_guard.rb +5 -7
- data/lib/dmarcator/query.rb +9 -8
- data/lib/dmarcator/record.rb +5 -7
- data/lib/dmarcator/report/auth_result.rb +1 -1
- data/lib/dmarcator/report/metadata.rb +4 -4
- data/lib/dmarcator/report/policy.rb +1 -1
- data/lib/dmarcator/report/reason.rb +1 -1
- data/lib/dmarcator/report/row.rb +4 -4
- data/lib/dmarcator/report.rb +2 -2
- data/lib/dmarcator/resolver/doh.rb +5 -4
- data/lib/dmarcator/resolver/dot.rb +6 -5
- data/lib/dmarcator/resolver/encrypted.rb +27 -0
- data/lib/dmarcator/resolver/plain.rb +9 -9
- data/lib/dmarcator/uri.rb +16 -13
- 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: 0d6972128ebbef3ee3a2307e376153701d3b3639f9ff2806d14350332d75c6e2
|
|
4
|
+
data.tar.gz: 084d6193d5fd84d6a0a0b16b18cb12c695f6d595bb7fb8f7424636d5bf996488
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e4ba02ebbd8af7fc1cdffe99f1ee4205e9eeae1005b0e3283f2c3730e52c05dcecdafd620e6d94ddf5b63e840ace61c32b34d653a7167f280366c847de6f8dcc
|
|
7
|
+
data.tar.gz: 3f3225eb2819332f1b71cfb3459d936c91765cd183db5158abcede1e82267fb3af33abe01392d437a64e5abb44e728c50f67015200e8078ccf9dce0a6d45e511
|
data/ChangeLog.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
### 1.7.1 / 2026-11-21
|
|
2
|
+
|
|
3
|
+
* `DMARCATOR_DNS_TIMEOUT` must be a positive integer. Zero or negative values now raise `ArgumentError` instead of building a resolver that times out immediately.
|
|
4
|
+
* The plaintext transport only retries on transport errors (`ResolutionError`, socket and I/O errors); an unexpected exception propagates instead of being retried across nameservers and reported as a DNS failure.
|
|
5
|
+
* A parsed `Uri` freezes its wrapped `URI` and itself, so `rua`/`ruf` values are fully immutable and the guarantee documented for 1.0.0 holds literally.
|
|
6
|
+
* Add a release-metadata spec keeping `VERSION`, `ChangeLog.md` and `SECURITY.md` in step.
|
|
7
|
+
* CI: audit dependencies with `bundler-audit`, randomize example order, test the minimum `nokogiri` (1.19.5), lint workflows with `actionlint` and `zizmor`, cancel superseded runs, cap job timeouts, and stop persisting checkout credentials.
|
|
8
|
+
* Add RuboCop (`rubocop`, `rubocop-performance`, `rubocop-rspec`) with a project config, and fix its findings: frozen `ATTRIBUTES` constants, `super()` in the resolver constructors, a shadowed `IPAddr::Error` rescue, safe navigation in `Report#version`, and layout corrections.
|
|
9
|
+
|
|
10
|
+
No public API changes.
|
|
11
|
+
|
|
12
|
+
### 1.7.0 / 2026-11-21
|
|
13
|
+
|
|
14
|
+
Behaviour changes, for RFC 7489 compliance:
|
|
15
|
+
|
|
16
|
+
* DMARC tag names and keyword values are now matched case-insensitively, as RFC 7489's ABNF (RFC 5234) requires. `P=REJECT`, `SP=Quarantine`, `ADKIM=S`, `RF=AFRF`, `FO=1:D` and `rua=mailto:d@example.com!10M` all parse, and the values are normalized to lower-case atoms (`record.p == :reject`). The version string remains exact: `v=dmarc1` is still rejected, while `V=DMARC1` is accepted because the tag name is case-insensitive. `DMARCator.dmarc` selects records that begin with the version tag under the same rules.
|
|
17
|
+
* A duplicate `v=` tag is now malformed and raises `InvalidRecord` in both modes. It was previously ignored in lenient mode.
|
|
18
|
+
* A known tag with an empty value is reported as `empty DMARC tag value` in strict mode instead of `unknown DMARC tag`.
|
|
19
|
+
* A `rua`/`ruf` size limit may now use up to 20 digits, provided it fits an unsigned 64-bit integer as RFC 7489 requires. The previous cap was ten digits.
|
|
20
|
+
* `DMARCator.validate_domain` caps a domain at 246 octets rather than 248, reserving the seven octets of the `_dmarc.` prefix within the 253-octet DNS name limit. Domains of 247 or 248 octets are now rejected.
|
|
21
|
+
|
|
22
|
+
The record-parser corpus has been regenerated to record these outcomes, and new cases cover mixed-case tags, mixed-case values and units, uint64 size limits, duplicate version tags and empty tag values.
|
|
23
|
+
|
|
1
24
|
### 1.6.1 / 2026-11-21
|
|
2
25
|
|
|
3
26
|
* `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.
|
data/README.md
CHANGED
|
@@ -241,6 +241,10 @@ DMARCator::Record.parse("v=DMARC1; p=none; pct=abc", strict: true)
|
|
|
241
241
|
# => DMARCator::InvalidRecord: invalid DMARC tag value: "pct=abc"
|
|
242
242
|
```
|
|
243
243
|
|
|
244
|
+
Tag names and keyword values are matched case-insensitively, as RFC 7489's
|
|
245
|
+
ABNF requires, and parsed values are normalized to lowercase atoms. The
|
|
246
|
+
version string is the exception: `DMARC1` is exact, so `v=dmarc1` is rejected.
|
|
247
|
+
|
|
244
248
|
## Parsing XML reports
|
|
245
249
|
|
|
246
250
|
Parse a DMARC aggregate/forensic report:
|
|
@@ -387,7 +391,7 @@ for the reporting policy and scope.
|
|
|
387
391
|
* A warning is emitted at load time if the bundled `resolv` gem is affected by
|
|
388
392
|
CVE-2026-80212/CVE-2026-80213.
|
|
389
393
|
* Domain names are validated before resolution (labels ≤ 63 octets, total ≤
|
|
390
|
-
|
|
394
|
+
246 octets, no leading/trailing hyphens).
|
|
391
395
|
* Optional [DNS over HTTPS and DNS over TLS](#dns-transport) transports verify
|
|
392
396
|
TLS certificates and fail closed: a transport failure raises
|
|
393
397
|
`DMARCator::ResolutionError` rather than being reported as a domain without a
|
|
@@ -48,8 +48,15 @@ module DMARCator
|
|
|
48
48
|
# Tags whose value is a list of mailto URIs.
|
|
49
49
|
URI_TAGS = %w[rua ruf].freeze
|
|
50
50
|
|
|
51
|
+
# Every tag the parser understands.
|
|
52
|
+
KNOWN_TAGS = (KEYWORD_TAGS.keys + DIGIT_TAGS.keys + %w[fo] + URI_TAGS).freeze
|
|
53
|
+
|
|
51
54
|
# The `v=` tag, which may only appear first.
|
|
52
|
-
|
|
55
|
+
#
|
|
56
|
+
# RFC 7489 spells the version with ABNF quoted strings and numeric
|
|
57
|
+
# terminals, so the tag name `v` is case-insensitive (RFC 5234) while the
|
|
58
|
+
# version string `DMARC1` is exact.
|
|
59
|
+
VERSION = /\A[vV][ \t]*=[ \t]*DMARC1\z/
|
|
53
60
|
|
|
54
61
|
# Characters allowed in a mailto local part and domain.
|
|
55
62
|
ADDRESS = /[A-Za-z0-9._%+-]+@[A-Za-z0-9._%+-]+/
|
|
@@ -105,10 +112,16 @@ module DMARCator
|
|
|
105
112
|
raise InvalidRecord, "duplicate DMARC tag: #{key}" if tags.key?(key)
|
|
106
113
|
|
|
107
114
|
tags[key] = value
|
|
115
|
+
when :version
|
|
116
|
+
raise InvalidRecord, 'duplicate DMARC version tag'
|
|
108
117
|
when :unknown
|
|
109
118
|
if strict
|
|
110
119
|
raise InvalidRecord, "unknown DMARC tag: #{truncate(segment).inspect}"
|
|
111
120
|
end
|
|
121
|
+
when :empty
|
|
122
|
+
if strict
|
|
123
|
+
raise InvalidRecord, "empty DMARC tag value: #{truncate(segment).inspect}"
|
|
124
|
+
end
|
|
112
125
|
when :invalid
|
|
113
126
|
if strict
|
|
114
127
|
raise InvalidRecord, "invalid DMARC tag value: #{truncate(segment).inspect}"
|
|
@@ -159,11 +172,17 @@ module DMARCator
|
|
|
159
172
|
|
|
160
173
|
return [:unknown] if value.nil?
|
|
161
174
|
|
|
162
|
-
name = name.sub(/[ \t]+\z/, '').sub(/\A[ \t]+/, '')
|
|
175
|
+
name = name.sub(/[ \t]+\z/, '').sub(/\A[ \t]+/, '').downcase(:ascii)
|
|
163
176
|
value = value.sub(/\A[ \t]+/, '').sub(/[ \t]+\z/, '')
|
|
164
177
|
|
|
165
|
-
#
|
|
166
|
-
|
|
178
|
+
# The version tag may only appear first, so a second one is a
|
|
179
|
+
# duplicate whatever its value.
|
|
180
|
+
return [:version] if name == 'v'
|
|
181
|
+
|
|
182
|
+
# An empty value is an error only for a tag the parser understands;
|
|
183
|
+
# an unknown tag is ignored either way.
|
|
184
|
+
return [:unknown] if value.empty? && !KNOWN_TAGS.include?(name)
|
|
185
|
+
return [:empty] if value.empty?
|
|
167
186
|
|
|
168
187
|
if (keywords = KEYWORD_TAGS[name])
|
|
169
188
|
keyword(name, keywords, value)
|
|
@@ -179,11 +198,13 @@ module DMARCator
|
|
|
179
198
|
end
|
|
180
199
|
|
|
181
200
|
def keyword(name, keywords, value)
|
|
182
|
-
|
|
201
|
+
folded = value.downcase(:ascii)
|
|
202
|
+
|
|
203
|
+
return [:ok, name.to_sym, folded.to_sym] if keywords.include?(folded)
|
|
183
204
|
|
|
184
205
|
# A known keyword followed by junk is a malformed record, not an
|
|
185
206
|
# invalid value: the value grammar matched and the remainder did not.
|
|
186
|
-
malformed!(value) if keywords.any? { |keyword|
|
|
207
|
+
malformed!(value) if keywords.any? { |keyword| folded.start_with?(keyword) }
|
|
187
208
|
|
|
188
209
|
[:invalid]
|
|
189
210
|
end
|
|
@@ -201,9 +222,10 @@ module DMARCator
|
|
|
201
222
|
end
|
|
202
223
|
|
|
203
224
|
def fo(value)
|
|
204
|
-
|
|
225
|
+
folded = value.downcase(:ascii)
|
|
226
|
+
return [:ok, :fo, folded.split(':')] if folded.match?(/\A[01ds](?::[01ds])*\z/)
|
|
205
227
|
|
|
206
|
-
malformed!(value) if
|
|
228
|
+
malformed!(value) if folded.match?(/\A[01ds](?::[01ds])*/)
|
|
207
229
|
|
|
208
230
|
[:invalid]
|
|
209
231
|
end
|
|
@@ -251,13 +273,17 @@ module DMARCator
|
|
|
251
273
|
size = unit = nil
|
|
252
274
|
|
|
253
275
|
if scanner.scan(/!/)
|
|
254
|
-
digits = scanner.scan(/\d{1,
|
|
276
|
+
digits = scanner.scan(/\d{1,20}/)
|
|
255
277
|
|
|
256
|
-
# A bare `!` or more than
|
|
278
|
+
# A bare `!` or more than twenty digits is an invalid value.
|
|
257
279
|
return nil if digits.nil? || scanner.match?(/\d/)
|
|
258
280
|
|
|
259
281
|
size = digits.to_i
|
|
260
|
-
|
|
282
|
+
|
|
283
|
+
# RFC 7489 requires the numeric portion to fit a uint64.
|
|
284
|
+
return nil if size > (2**64) - 1
|
|
285
|
+
|
|
286
|
+
unit = scanner.scan(/[kmgt]/i)&.downcase(:ascii)&.to_sym
|
|
261
287
|
|
|
262
288
|
# A second `!` is an invalid value.
|
|
263
289
|
return nil if scanner.match?(/!/)
|
|
@@ -193,8 +193,8 @@ module DMARCator
|
|
|
193
193
|
stack.pop
|
|
194
194
|
end
|
|
195
195
|
end
|
|
196
|
-
rescue Nokogiri::XML::SyntaxError =>
|
|
197
|
-
raise InvalidReport, sanitize_syntax_error(
|
|
196
|
+
rescue Nokogiri::XML::SyntaxError => error
|
|
197
|
+
raise InvalidReport, sanitize_syntax_error(error)
|
|
198
198
|
end
|
|
199
199
|
|
|
200
200
|
def enforce(setting, value)
|
|
@@ -221,11 +221,9 @@ module DMARCator
|
|
|
221
221
|
end
|
|
222
222
|
|
|
223
223
|
def parse_document
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
rescue Nokogiri::XML::SyntaxError => e
|
|
228
|
-
raise InvalidReport, sanitize_syntax_error(e)
|
|
224
|
+
Nokogiri::XML.parse(@xml, nil, nil, self.class.parse_options)
|
|
225
|
+
rescue Nokogiri::XML::SyntaxError => error
|
|
226
|
+
raise InvalidReport, sanitize_syntax_error(error)
|
|
229
227
|
end
|
|
230
228
|
end
|
|
231
229
|
end
|
data/lib/dmarcator/query.rb
CHANGED
|
@@ -69,10 +69,10 @@ module DMARCator
|
|
|
69
69
|
#
|
|
70
70
|
# Validates a domain before using it in a DNS query.
|
|
71
71
|
#
|
|
72
|
-
# Rejects underscores and enforces the DNS length and label limits,
|
|
73
|
-
#
|
|
74
|
-
#
|
|
75
|
-
# labels.
|
|
72
|
+
# Rejects underscores and enforces the DNS length and label limits, reserving
|
|
73
|
+
# the seven octets of the `_dmarc.` prefix that {dmarc} adds. This is the
|
|
74
|
+
# validator for registrable domains rather than arbitrary DNS names; use
|
|
75
|
+
# {validate_txt_name} for service labels.
|
|
76
76
|
#
|
|
77
77
|
# @param [String] domain
|
|
78
78
|
# The domain to validate.
|
|
@@ -85,7 +85,7 @@ module DMARCator
|
|
|
85
85
|
#
|
|
86
86
|
def self.validate_domain(domain)
|
|
87
87
|
unless domain.is_a?(String) && !domain.empty? &&
|
|
88
|
-
domain.length <=
|
|
88
|
+
domain.length <= 246 &&
|
|
89
89
|
!domain.start_with?('.') &&
|
|
90
90
|
!domain.include?('..') &&
|
|
91
91
|
!domain.match?(/[^A-Za-z0-9.-]/) &&
|
|
@@ -249,12 +249,13 @@ module DMARCator
|
|
|
249
249
|
def self.dmarc(domain, resolver: default_resolver)
|
|
250
250
|
name = "_dmarc.#{validate_domain(domain)}"
|
|
251
251
|
|
|
252
|
-
# Per RFC 7489 §6.6.3, use the TXT record
|
|
253
|
-
#
|
|
252
|
+
# Per RFC 7489 §6.6.3, use the TXT record that starts with the `v=` tag for
|
|
253
|
+
# DMARC1. Tag names are case-insensitive (RFC 5234), so `V=` matches; the
|
|
254
|
+
# version string `DMARC1` is exact.
|
|
254
255
|
dmarc_records = lookup_txt(name, resolver: resolver).map do |record|
|
|
255
256
|
record.strings.join
|
|
256
257
|
end.select do |text|
|
|
257
|
-
text.
|
|
258
|
+
text.b.match?(/\A[vV][ \t]*=[ \t]*DMARC1[ \t]*(?:;|\z)/)
|
|
258
259
|
end
|
|
259
260
|
|
|
260
261
|
dmarc_records.first if dmarc_records.one?
|
data/lib/dmarcator/record.rb
CHANGED
|
@@ -13,7 +13,6 @@ module DMARCator
|
|
|
13
13
|
# @see https://www.rfc-editor.org/rfc/rfc7489
|
|
14
14
|
#
|
|
15
15
|
class Record
|
|
16
|
-
|
|
17
16
|
# `p` field.
|
|
18
17
|
#
|
|
19
18
|
# @return [:none, :quarantine, :reject]
|
|
@@ -66,7 +65,7 @@ module DMARCator
|
|
|
66
65
|
#
|
|
67
66
|
# @option attributes [:DMARC1] :v
|
|
68
67
|
#
|
|
69
|
-
def initialize(attributes={})
|
|
68
|
+
def initialize(attributes = {})
|
|
70
69
|
@v = attributes.fetch(:v)
|
|
71
70
|
@adkim = attributes[:adkim]
|
|
72
71
|
@aspf = attributes[:aspf]
|
|
@@ -209,7 +208,7 @@ module DMARCator
|
|
|
209
208
|
|
|
210
209
|
#
|
|
211
210
|
# `rf` field.
|
|
212
|
-
#
|
|
211
|
+
#
|
|
213
212
|
# @return [:afrf, :iodef]
|
|
214
213
|
# The value of the `rf=` field, or `:afrf` if the field was omitted.
|
|
215
214
|
#
|
|
@@ -235,7 +234,7 @@ module DMARCator
|
|
|
235
234
|
# The value of the `ri=` field, or `86400` if the field was omitted.
|
|
236
235
|
#
|
|
237
236
|
def ri
|
|
238
|
-
@ri ||
|
|
237
|
+
@ri || 86_400
|
|
239
238
|
end
|
|
240
239
|
|
|
241
240
|
#
|
|
@@ -343,7 +342,7 @@ module DMARCator
|
|
|
343
342
|
hash[:rf] = @rf if @rf
|
|
344
343
|
hash[:pct] = @pct if @pct
|
|
345
344
|
|
|
346
|
-
|
|
345
|
+
hash
|
|
347
346
|
end
|
|
348
347
|
|
|
349
348
|
#
|
|
@@ -366,8 +365,7 @@ module DMARCator
|
|
|
366
365
|
tags << "rf=#{@rf}" if @rf
|
|
367
366
|
tags << "pct=#{@pct}" if @pct
|
|
368
367
|
|
|
369
|
-
|
|
368
|
+
tags.join('; ')
|
|
370
369
|
end
|
|
371
|
-
|
|
372
370
|
end
|
|
373
371
|
end
|
|
@@ -11,7 +11,7 @@ module DMARCator
|
|
|
11
11
|
include Internal::XmlHelper
|
|
12
12
|
|
|
13
13
|
# Attribute names exposed by this class.
|
|
14
|
-
ATTRIBUTES = [
|
|
14
|
+
ATTRIBUTES = %i[type domain result selector scope].freeze
|
|
15
15
|
|
|
16
16
|
# @!attribute [r] type
|
|
17
17
|
# @return [String] the entry name (`dkim` or `spf`).
|
|
@@ -11,10 +11,10 @@ module DMARCator
|
|
|
11
11
|
include Internal::XmlHelper
|
|
12
12
|
|
|
13
13
|
# Attribute names exposed by this class.
|
|
14
|
-
ATTRIBUTES = [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
]
|
|
14
|
+
ATTRIBUTES = %i[
|
|
15
|
+
org_name email extra_contact_info report_id
|
|
16
|
+
begin_at end_at errors
|
|
17
|
+
].freeze
|
|
18
18
|
|
|
19
19
|
# @!attribute [r] org_name
|
|
20
20
|
# @return [String, nil] the reporting organization.
|
|
@@ -11,7 +11,7 @@ module DMARCator
|
|
|
11
11
|
include Internal::XmlHelper
|
|
12
12
|
|
|
13
13
|
# Attribute names exposed by this class.
|
|
14
|
-
ATTRIBUTES = [
|
|
14
|
+
ATTRIBUTES = %i[domain adkim aspf p sp pct fo].freeze
|
|
15
15
|
|
|
16
16
|
# @!attribute [r] domain
|
|
17
17
|
# @return [String, nil] the domain the policy applies to.
|
data/lib/dmarcator/report/row.rb
CHANGED
|
@@ -16,10 +16,10 @@ module DMARCator
|
|
|
16
16
|
include Internal::XmlHelper
|
|
17
17
|
|
|
18
18
|
# Attribute names exposed by this class.
|
|
19
|
-
ATTRIBUTES = [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
]
|
|
19
|
+
ATTRIBUTES = %i[
|
|
20
|
+
source_ip count disposition dkim spf
|
|
21
|
+
envelope_to envelope_from header_from
|
|
22
|
+
].freeze
|
|
23
23
|
|
|
24
24
|
# @!attribute [r] source_ip
|
|
25
25
|
# @return [String, nil] the sending IP address.
|
data/lib/dmarcator/report.rb
CHANGED
|
@@ -101,9 +101,9 @@ module DMARCator
|
|
|
101
101
|
|
|
102
102
|
@version = begin
|
|
103
103
|
value = get_text('feedback/version')
|
|
104
|
-
value = value
|
|
104
|
+
value = value&.strip
|
|
105
105
|
|
|
106
|
-
value.freeze if value
|
|
106
|
+
value.freeze if value&.match?(/\A\d+(?:\.\d+)*\z/)
|
|
107
107
|
end
|
|
108
108
|
end
|
|
109
109
|
|
|
@@ -49,7 +49,8 @@ module DMARCator
|
|
|
49
49
|
# @return [DoH]
|
|
50
50
|
#
|
|
51
51
|
# @raise [ArgumentError]
|
|
52
|
-
# `DMARCATOR_DOH_URL` is missing or not an HTTPS URL
|
|
52
|
+
# `DMARCATOR_DOH_URL` is missing or not an HTTPS URL, or
|
|
53
|
+
# `DMARCATOR_DNS_TIMEOUT` is not a positive integer.
|
|
53
54
|
#
|
|
54
55
|
def self.from_env(env = ENV)
|
|
55
56
|
url = env['DMARCATOR_DOH_URL']
|
|
@@ -70,12 +71,12 @@ module DMARCator
|
|
|
70
71
|
end
|
|
71
72
|
|
|
72
73
|
def self.timeout_from(env)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
value.nil? || value.empty? ? DEFAULT_TIMEOUT : Integer(value, 10)
|
|
74
|
+
super(env, DEFAULT_TIMEOUT)
|
|
76
75
|
end
|
|
77
76
|
|
|
78
77
|
def initialize(url:, ipaddr: nil, timeout: DEFAULT_TIMEOUT)
|
|
78
|
+
super()
|
|
79
|
+
|
|
79
80
|
@url = URI.parse(url)
|
|
80
81
|
|
|
81
82
|
unless @url.is_a?(URI::HTTPS) && @url.host
|
|
@@ -47,7 +47,8 @@ module DMARCator
|
|
|
47
47
|
# @return [DoT]
|
|
48
48
|
#
|
|
49
49
|
# @raise [ArgumentError]
|
|
50
|
-
# `DMARCATOR_DOT_SERVER` is missing or malformed
|
|
50
|
+
# `DMARCATOR_DOT_SERVER` is missing or malformed, or
|
|
51
|
+
# `DMARCATOR_DNS_TIMEOUT` is not a positive integer.
|
|
51
52
|
#
|
|
52
53
|
def self.from_env(env = ENV)
|
|
53
54
|
server = env['DMARCATOR_DOT_SERVER']
|
|
@@ -88,12 +89,12 @@ module DMARCator
|
|
|
88
89
|
end
|
|
89
90
|
|
|
90
91
|
def self.timeout_from(env)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
value.nil? || value.empty? ? DEFAULT_TIMEOUT : Integer(value, 10)
|
|
92
|
+
super(env, DEFAULT_TIMEOUT)
|
|
94
93
|
end
|
|
95
94
|
|
|
96
95
|
def initialize(host:, port: DEFAULT_PORT, sni: nil, timeout: DEFAULT_TIMEOUT)
|
|
96
|
+
super()
|
|
97
|
+
|
|
97
98
|
@host = host
|
|
98
99
|
@port = port
|
|
99
100
|
@sni = sni || host
|
|
@@ -151,7 +152,7 @@ module DMARCator
|
|
|
151
152
|
IPAddr.new(value.to_s)
|
|
152
153
|
|
|
153
154
|
true
|
|
154
|
-
rescue
|
|
155
|
+
rescue ArgumentError
|
|
155
156
|
false
|
|
156
157
|
end
|
|
157
158
|
|
|
@@ -24,6 +24,33 @@ module DMARCator
|
|
|
24
24
|
# Maximum number of CNAME indirections to follow.
|
|
25
25
|
MAX_CNAME_DEPTH = 8
|
|
26
26
|
|
|
27
|
+
#
|
|
28
|
+
# Reads a positive connect/read timeout in seconds from the environment.
|
|
29
|
+
#
|
|
30
|
+
# @param [Hash] env
|
|
31
|
+
# @param [Integer] default
|
|
32
|
+
# The timeout used when `DMARCATOR_DNS_TIMEOUT` is unset or empty.
|
|
33
|
+
#
|
|
34
|
+
# @return [Integer]
|
|
35
|
+
#
|
|
36
|
+
# @raise [ArgumentError]
|
|
37
|
+
# `DMARCATOR_DNS_TIMEOUT` is not a positive integer.
|
|
38
|
+
#
|
|
39
|
+
def self.timeout_from(env, default)
|
|
40
|
+
value = env['DMARCATOR_DNS_TIMEOUT']
|
|
41
|
+
|
|
42
|
+
return default if value.nil? || value.empty?
|
|
43
|
+
|
|
44
|
+
timeout = Integer(value, 10)
|
|
45
|
+
|
|
46
|
+
unless timeout.positive?
|
|
47
|
+
raise ArgumentError,
|
|
48
|
+
"DMARCATOR_DNS_TIMEOUT must be a positive integer, got #{value.inspect}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
timeout
|
|
52
|
+
end
|
|
53
|
+
|
|
27
54
|
#
|
|
28
55
|
# Looks up resource records, matching `Resolv::DNS#getresources`.
|
|
29
56
|
#
|
|
@@ -43,16 +43,14 @@ module DMARCator
|
|
|
43
43
|
# @return [Plain]
|
|
44
44
|
#
|
|
45
45
|
# @raise [ArgumentError]
|
|
46
|
-
# `DMARCATOR_DNS_TIMEOUT` is not
|
|
46
|
+
# `DMARCATOR_DNS_TIMEOUT` is not a positive integer.
|
|
47
47
|
#
|
|
48
48
|
def self.from_env(env = ENV)
|
|
49
49
|
new(timeout: timeout_from(env))
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def self.timeout_from(env)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
value.nil? || value.empty? ? DEFAULT_TIMEOUT : Integer(value, 10)
|
|
53
|
+
super(env, DEFAULT_TIMEOUT)
|
|
56
54
|
end
|
|
57
55
|
|
|
58
56
|
#
|
|
@@ -74,6 +72,8 @@ module DMARCator
|
|
|
74
72
|
end
|
|
75
73
|
|
|
76
74
|
def initialize(nameservers: nil, timeout: DEFAULT_TIMEOUT)
|
|
75
|
+
super()
|
|
76
|
+
|
|
77
77
|
@nameservers = (nameservers || self.class.system_nameservers).freeze
|
|
78
78
|
@timeout = timeout
|
|
79
79
|
|
|
@@ -87,11 +87,11 @@ module DMARCator
|
|
|
87
87
|
last_error = nil
|
|
88
88
|
|
|
89
89
|
@nameservers.each do |host, port|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
return request(host, port, wire)
|
|
91
|
+
rescue ResolutionError, SystemCallError, SocketError, IOError => error
|
|
92
|
+
# Try the remaining nameservers, but do not swallow an error that
|
|
93
|
+
# indicates a bug in the transport.
|
|
94
|
+
last_error = error
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
raise ResolutionError,
|
data/lib/dmarcator/uri.rb
CHANGED
|
@@ -9,7 +9,6 @@ module DMARCator
|
|
|
9
9
|
# @since 0.5.0
|
|
10
10
|
#
|
|
11
11
|
class Uri
|
|
12
|
-
|
|
13
12
|
# The `mailto:` URI.
|
|
14
13
|
#
|
|
15
14
|
# @return [URI::MailTo]
|
|
@@ -28,6 +27,9 @@ module DMARCator
|
|
|
28
27
|
#
|
|
29
28
|
# Initializes the DMARC URI.
|
|
30
29
|
#
|
|
30
|
+
# The wrapped URI is frozen, and so is the value object, so a parsed URI
|
|
31
|
+
# cannot be mutated after construction.
|
|
32
|
+
#
|
|
31
33
|
# @param [URI::MailTo] uri
|
|
32
34
|
# The `mailto:` URI.
|
|
33
35
|
#
|
|
@@ -37,11 +39,13 @@ module DMARCator
|
|
|
37
39
|
# @param [:k, :m, :g, :t] unit
|
|
38
40
|
# The optional size unit.
|
|
39
41
|
#
|
|
40
|
-
def initialize(uri,size=nil,unit=nil)
|
|
41
|
-
@uri = uri
|
|
42
|
+
def initialize(uri, size = nil, unit = nil)
|
|
43
|
+
@uri = uri.freeze
|
|
42
44
|
|
|
43
45
|
@size = size
|
|
44
46
|
@unit = unit
|
|
47
|
+
|
|
48
|
+
freeze
|
|
45
49
|
end
|
|
46
50
|
|
|
47
51
|
#
|
|
@@ -72,9 +76,9 @@ module DMARCator
|
|
|
72
76
|
#
|
|
73
77
|
def ==(other)
|
|
74
78
|
(self.class == other.class) &&
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
(@uri == other.uri) &&
|
|
80
|
+
(@size == other.size) &&
|
|
81
|
+
(@unit == other.unit)
|
|
78
82
|
end
|
|
79
83
|
|
|
80
84
|
#
|
|
@@ -106,13 +110,13 @@ module DMARCator
|
|
|
106
110
|
def to_s
|
|
107
111
|
str = @uri.to_s
|
|
108
112
|
|
|
109
|
-
if
|
|
113
|
+
if @size || @unit
|
|
110
114
|
str << "!"
|
|
111
|
-
str <<
|
|
112
|
-
str <<
|
|
115
|
+
str << @size.to_s if @size
|
|
116
|
+
str << @unit.to_s if @unit
|
|
113
117
|
end
|
|
114
118
|
|
|
115
|
-
|
|
119
|
+
str
|
|
116
120
|
end
|
|
117
121
|
|
|
118
122
|
#
|
|
@@ -138,10 +142,10 @@ module DMARCator
|
|
|
138
142
|
# Private methods are not forwarded: delegation is limited to the wrapped
|
|
139
143
|
# URI's public interface.
|
|
140
144
|
#
|
|
141
|
-
def method_missing(name
|
|
145
|
+
def method_missing(name, *arguments, &block)
|
|
142
146
|
return super unless @uri.respond_to?(name)
|
|
143
147
|
|
|
144
|
-
@uri.public_send(name
|
|
148
|
+
@uri.public_send(name, *arguments, &block)
|
|
145
149
|
end
|
|
146
150
|
|
|
147
151
|
#
|
|
@@ -152,6 +156,5 @@ module DMARCator
|
|
|
152
156
|
def respond_to_missing?(name, include_private = false)
|
|
153
157
|
@uri.respond_to?(name) || super
|
|
154
158
|
end
|
|
155
|
-
|
|
156
159
|
end
|
|
157
160
|
end
|
data/lib/dmarcator/version.rb
CHANGED