dmarcator 1.7.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 558d54a036ce3eb0d8664fc284cd62e0333b7204c07f6ed825b4cdb1d0a2d20f
4
- data.tar.gz: 28c8d4ac1d67cc23412261a3e8efba82dc5fb72f94aaa3b02a8f866a25999c3c
3
+ metadata.gz: 0d6972128ebbef3ee3a2307e376153701d3b3639f9ff2806d14350332d75c6e2
4
+ data.tar.gz: 084d6193d5fd84d6a0a0b16b18cb12c695f6d595bb7fb8f7424636d5bf996488
5
5
  SHA512:
6
- metadata.gz: 240ed6386e53a130689da6f5b34e710524f390d89c7cbb511907804ed41b47cb6294a532b3c50db5c82eb3929e24e552eddd275d4516c31a9446703593c12899
7
- data.tar.gz: 8cc32742b0db5c2f77389634de14acc93350315786d208f4d45a46fcc67793621a69a38d657e13fdeb9b2d6e782d28ab7f1994eb5d2a43cc320675ce16696931
6
+ metadata.gz: e4ba02ebbd8af7fc1cdffe99f1ee4205e9eeae1005b0e3283f2c3730e52c05dcecdafd620e6d94ddf5b63e840ace61c32b34d653a7167f280366c847de6f8dcc
7
+ data.tar.gz: 3f3225eb2819332f1b71cfb3459d936c91765cd183db5158abcede1e82267fb3af33abe01392d437a64e5abb44e728c50f67015200e8078ccf9dce0a6d45e511
data/ChangeLog.md CHANGED
@@ -1,3 +1,14 @@
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
+
1
12
  ### 1.7.0 / 2026-11-21
2
13
 
3
14
  Behaviour changes, for RFC 7489 compliance:
@@ -193,8 +193,8 @@ module DMARCator
193
193
  stack.pop
194
194
  end
195
195
  end
196
- rescue Nokogiri::XML::SyntaxError => e
197
- raise InvalidReport, sanitize_syntax_error(e)
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
- document = Nokogiri::XML.parse(@xml, nil, nil, self.class.parse_options)
225
-
226
- document
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
@@ -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 || 86400
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
- return hash
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
- return tags.join('; ')
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 = [:type, :domain, :result, :selector, :scope]
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
- :org_name, :email, :extra_contact_info, :report_id,
16
- :begin_at, :end_at, :errors
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 = [:domain, :adkim, :aspf, :p, :sp, :pct, :fo]
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.
@@ -11,7 +11,7 @@ module DMARCator
11
11
  include Internal::XmlHelper
12
12
 
13
13
  # Attribute names exposed by this class.
14
- ATTRIBUTES = [:type, :comment]
14
+ ATTRIBUTES = %i[type comment].freeze
15
15
 
16
16
  # @!attribute [r] type
17
17
  # @return [String, nil] the reason type.
@@ -16,10 +16,10 @@ module DMARCator
16
16
  include Internal::XmlHelper
17
17
 
18
18
  # Attribute names exposed by this class.
19
- ATTRIBUTES = [
20
- :source_ip, :count, :disposition, :dkim, :spf,
21
- :envelope_to, :envelope_from, :header_from
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.
@@ -101,9 +101,9 @@ module DMARCator
101
101
 
102
102
  @version = begin
103
103
  value = get_text('feedback/version')
104
- value = value.strip if value
104
+ value = value&.strip
105
105
 
106
- value.freeze if value && value.match?(/\A\d+(?:\.\d+)*\z/)
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
- value = env['DMARCATOR_DNS_TIMEOUT']
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
- value = env['DMARCATOR_DNS_TIMEOUT']
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 IPAddr::Error, ArgumentError
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 an integer.
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
- value = env['DMARCATOR_DNS_TIMEOUT']
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
- begin
91
- return request(host, port, wire)
92
- rescue StandardError => error
93
- last_error = error
94
- end
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
- (@uri == other.uri) &&
76
- (@size == other.size) &&
77
- (@unit == other.unit)
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 (@size || @unit)
113
+ if @size || @unit
110
114
  str << "!"
111
- str << "#{@size}" if @size
112
- str << "#{@unit}" if @unit
115
+ str << @size.to_s if @size
116
+ str << @unit.to_s if @unit
113
117
  end
114
118
 
115
- return str
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,*arguments,&block)
145
+ def method_missing(name, *arguments, &block)
142
146
  return super unless @uri.respond_to?(name)
143
147
 
144
- @uri.public_send(name,*arguments,&block)
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module DMARCator
4
4
  # dmarcator version
5
- VERSION = '1.7.0'
5
+ VERSION = '1.7.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.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Berman